我有一个列(名为组)作为分组信息(1 到 4 代表 4 个组),我希望用它来为图中的组分配不同的颜色
x=data.frame(read.csv(file.choose()))
plot(x$A,x$B,col=as.factor(x$group))
Run Code Online (Sandbox Code Playgroud)
对于标记为 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)))
Run Code Online (Sandbox Code Playgroud)