plotting in different shapes using pch= argument
Asked Answered
B

1

18

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 ?

Boettcher answered 16/10, 2012 at 17:0 Comment(0)
T
40

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:

enter image description here

Traynor answered 16/10, 2012 at 17:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.