plotting in different shapes using pch= argument

淺唱寂寞╮ 提交于 2019-12-03 05:13:40

问题


If I am using R to plot. How can I assign a particular shape to data points belonging to one category (using the pch argument to plot()) based on a column in my data frame that has the categorical data? Will using as.factor() to group data and then using pch help ?


回答1:


You mean something like this...?

plot(Sepal.Length ~ Petal.Length,
      xlab = "Petal Length (cm)",
      ylab = "Sepal Length (cm)",
      pch = c(16, 17, 18)[as.numeric(Species)],  # different 'pch' types 
      main = "Anderson Iris Dataset",
      col = c("red", "green","blue")[as.numeric(Species)],
      data = iris)

Which produces:



来源:https://stackoverflow.com/questions/12919816/plotting-in-different-shapes-using-pch-argument

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!