我似乎无法通过以下方式更改颜色编码:
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]&#34;蓝色&#34; &#34;蓝色&#34; &#34;蓝色&#34; &#34;蓝色&#34; &#34;蓝色&#34; &#34;蓝色&#34; &#34;蓝色&#34; &#34;蓝色&#34; &#34;蓝色&#34; &#34;蓝色&#34; &#34;蓝色&#34; &#34;蓝色&#34; &#34;蓝色&#34; &#34;蓝色&#34; &#34;蓝色&#34; &#34;蓝色&#34; &#34;蓝色&#34; &#34;蓝色&#34; &#34;绿色&#34; &#34;蓝色&#34; &#34;绿色&#34; [22]&#34;绿色&#34; &#34;绿色&#34; &#34;绿色&#34; &#34;绿色&#34; &#34;绿色&#34; &#34;绿色&#34; &#34;绿色&#34;
但在图表上显示黑点和红点。如何解决这个问题?
(之前我用4个类别尝试了这个,我在cols0中使用了4种颜色,并且有效)
答案 0 :(得分:1)
当您想要在绘图函数中调用cols0时,您正在调用groups0作为颜色:
plot(x, y,
main= "",
ylab= "",
xlab= "",
col= cols0, pch = 19, cex = 2, lty = "solid", lwd = 2)
此外,如果cols0的唯一输入是“红色”和“绿色”,目前还不清楚你从哪里获得“蓝色”。