Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用我选择的颜色在R中按组打印?_R_Plot_Colors - Fatal编程技术网

如何使用我选择的颜色在R中按组打印?

如何使用我选择的颜色在R中按组打印?,r,plot,colors,R,Plot,Colors,我有一个列(命名组)作为分组信息(4个组为1到4),我希望使用它为绘图中的组分配不同的颜色 x=data.frame(read.csv(file.choose())) plot(x$A,x$B,col=as.factor(x$group)) 这将为标记为1、2、3的组提供黑色、红色、绿色等颜色。。。分别地如果我想根据我的愿望设计颜色,我该如何修改代码。假设我希望标记为1的组以蓝色显示(例如)如下所示: plot(Sepal.Length ~ Sepal.Width, data = iris,

我有一个列(命名组)作为分组信息(4个组为1到4),我希望使用它为绘图中的组分配不同的颜色

x=data.frame(read.csv(file.choose()))
plot(x$A,x$B,col=as.factor(x$group))
这将为标记为1、2、3的组提供黑色、红色、绿色等颜色。。。分别地如果我想根据我的愿望设计颜色,我该如何修改代码。假设我希望标记为1的组以蓝色显示(例如)

如下所示:

plot(Sepal.Length ~ Sepal.Width, data = iris, 
     col = c("blue", "red", "green")[as.factor(Species)])
legend("topright", pch = 1, col = c("blue", "red", "green"),
       legend = levels(as.factor(iris$Species)))