【发布时间】: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))工作正常,因此我们确实需要您的所有数据来提供帮助。