Colouring plot by factor in R

后端 未结 6 1570
执念已碎
执念已碎 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条回答
  •  萌比男神i
    2020-12-02 16:20

    The lattice library is another good option. Here I've added a legend on the right side and jittered the points because some of them overlapped.

    xyplot(Sepal.Width ~ Sepal.Length, group=Species, data=iris, 
           auto.key=list(space="right"), 
           jitter.x=TRUE, jitter.y=TRUE)
    

    example plot

提交回复
热议问题