使用pch =参数绘制不同形状的图形

问题描述:

如果我使用R绘图。如何为属于一个类别的数据点分配特定的形状(使用 plot() pch 参数)基于我的数据框中具有分类数据的列?将使用 as.factor()对数据进行分组,然后使用 pch 帮助吗?

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 ?

您的意思是这样的...?

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)

哪个会产生: