M. Aberle M. Aberle - 1 month ago 6
R Question

Read and assign pch values from .csv

I have a rather large data set (.csv), in which one column includes the preferred pch value for plotting points in R.

So far the code

pch = c(21,21,21,21,23,23,23,23)[unclass(MSP_SI_output.df$Group_ID)],
is working, however isn't ideal.

Is there a way to read the preferred pch values in the .csv file and assign them accordingly in the plot? For instance, the pch values are located at
MSP_SI_output.df$pch


Your help is greatly appreciated.

Answer

Are you looking for something like this?

a = data.frame(x = c(1,2,3,4),y = c(3,4,5,6), z = c(20,21,22,23))
> a
  x y  z
1 1 3 20
2 2 4 21
3 3 5 22
4 4 6 23

plot(a$x, a$y, pch = a$z)

enter image description here

Comments