Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

plotting in different shapes using pch= argument

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 ?

like image 664
Anurag Mishra Avatar asked Oct 16 '12 17:10

Anurag Mishra


People also ask

How do you plot different shapes in R?

In the R Language, we can use “+”, “*“,”-“,”. “,”#, “%”, and “o” for plotting different symbols.

What is the significance of having plotting character PCH in R?

Plot character or pch is the standard argument to set the character that will be plotted in a number of R functions. Explanatory text can be added to a plot in several different forms, including axis labels, titles, legends, or a text added to the plot itself.

What is PCH in R plot?

The pch stands for plot character. The pch contains numeric values rangers from 0 to 25 or character symbols (“+”, “.”, “;”, etc.) specifying in symbols (or shapes). The pch is the standard argument to set the character plotted in several R functions.

How do you change plot symbols in R?

Change R base plot point shapes The default R plot pch symbol is 1, which is an empty circle. You can change this to pch = 19 (solid circle) or to pch = 21 (filled circle). To change the color and the size of points, use the following arguments: col : color (hexadecimal color code or color name).


1 Answers

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

like image 113
Jilber Urbina Avatar answered Sep 20 '22 06:09

Jilber Urbina