【问题标题】:Colour coding does not change colours in plot function颜色编码不会改变绘图功能中的颜色
【发布时间】:2015-08-31 21:01:05
【问题描述】:

我似乎无法使用以下代码更改颜色编码:

groups0 = factor(gsub('(.).', '\\1', country))

cols0 = c('green','red')[groups0]

plot(x, y,
 main= "",
 ylab= "",
 xlab= "",
 col= groups0, pch = 19, cex = 2, lty = "solid", lwd = 2)

reg1 <- lm(y ~ x)

text(x, y , labels=datta$City,pos = 4, cex= 0.5); abline(reg1)

cols0 返回:

cols0 [1] “蓝色” “蓝色” “蓝色” “蓝色” “蓝色” “蓝色” “蓝色” “蓝色” “蓝色” “蓝色” “蓝色” “蓝色” “蓝色” “蓝色” “蓝色” “蓝色” “蓝色”“蓝色”“绿色”“蓝色”“绿色” [22] “绿色” “绿色” “绿色” “绿色” “绿色” “绿色” “绿色”

但在图表上,它显示了黑点和红点。如何解决这个问题?

(我之前试过用4个分类,在cols0中用了四种颜色,效果不错)

【问题讨论】:

  • plot(mtcars$wt, mtcars$mpg, main="", ylab="", xlab="", pch=19, cex=2, lty="solid", lwd=2, col=sample(c("blue", "green"), nrow(mtcars), replace=TRUE)) 工作正常,因此我们确实需要您的所有数据来提供帮助。

标签: r colors


【解决方案1】:

当您似乎想在绘图函数中调用 cols0 时,您正在为颜色调用 groups0:

plot(x, y,
 main= "",
 ylab= "",
 xlab= "",
 col= cols0, pch = 19, cex = 2, lty = "solid", lwd = 2)

此外,如果 cols0 的唯一输入是“红色”和“绿色”,则不清楚您从哪里获得“蓝色”。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-22
    • 1970-01-01
    • 1970-01-01
    • 2022-01-01
    • 1970-01-01
    • 2016-09-11
    • 1970-01-01
    • 2012-01-23
    相关资源
    最近更新 更多