按 R 中的因子着色图 [英] Colouring plot by factor in R
本文介绍了按 R 中的因子着色图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在制作两个变量的散点图,并希望通过因子变量为点着色.这是一些可重现的代码:
I am making a scatter plot of two variables and would like to colour the points by a factor variable. Here is some reproducible code:
data <- iris
plot(data$Sepal.Length, data$Sepal.Width, col=data$Species)
这一切都很好,但我怎么知道什么因素被染上了什么颜色??
This is all well and good but how do I know what factor has been coloured what colour??
推荐答案
data<-iris
plot(data$Sepal.Length, data$Sepal.Width, col=data$Species)
legend(7,4.3,unique(data$Species),col=1:length(data$Species),pch=1)
应该为你做.但我更喜欢 ggplot2
并建议在 R 中获得更好的图形.
should do it for you. But I prefer ggplot2
and would suggest that for better graphics in R.
这篇关于按 R 中的因子着色图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文