Colouring plot by factor in R

后端 未结 6 1589
执念已碎
执念已碎 2020-12-02 15:21

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(da         


        
6条回答
  •  南笙
    南笙 (楼主)
    2020-12-02 16:24

    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)
    

    should do it for you. But I prefer ggplot2 and would suggest that for better graphics in R.

提交回复
热议问题