Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R- plot numbers instead of points

Tags:

plot

r

scatter

I have successfully made a scatterplot, with different symbols for each data series. But what I want to do is make the same scatterplot with the point to show up as numbers. Not the value of each point, just an assigned number.

As of right now, I have three depths I am plotting (0, 3, 6cm). I have all my 0cm as triangles, etc. I want my 0cm points to be the character 0, the 3cm points to show up as 3, and the 6cm points to show up as 6.

Is this possible?

like image 981
Valerie S Avatar asked Jul 25 '13 13:07

Valerie S


People also ask

How do you plot a line instead of dots in R?

The basic plot command Here, we use type="l" to plot a line rather than symbols, change the color to green, make the line width be 5, specify different labels for the x and y axis, and add a title (with the main argument).

How do you show the value of a plot in R?

Method 1: Displaying only values using text() function in Plot. In this function user just need to call the text() function with the specified parameters into it after calling the plot() function in R language and this process will lead to a plot of the provided points by the user with the values in the plot.

What does PCH mean in R?

Share. 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.

How do I change the size of the PCH in R?

You can change the pch size in R with the cex argument. Default value is 1.


1 Answers

You can use text. Using @HongOoi data:

dat <- data.frame(x=rnorm(100), y1=rnorm(100)-1, y2=rnorm(100), y3=rnorm(100)+1)
plot(y1 ~ x, data=dat, type='n', ylim=c(-4, 4))     
text(dat$x,dat$y1,label=0,col='blue')
text(dat$x,dat$y2,label=1,col='green')
text(dat$x,dat$y3,label=2,,col='red')

enter image description here

like image 135
agstudy Avatar answered Sep 21 '22 15:09

agstudy