Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display Values in R Plot

Tags:

plot

r

How can I render the value of points in a plot in the plot itself?

Thank you.

like image 554
omarish Avatar asked Sep 19 '09 19:09

omarish


People also ask

How do you show values in a graph in R?

Displaying only values using text() function in Plot. Displaying only values using geom_text() function from ggplot2 Package in Plot.

How do I add labels to a plot in R?

Use the title( ) function to add labels to a plot. Many other graphical parameters (such as text size, font, rotation, and color) can also be specified in the title( ) function. # labels 25% smaller than the default and green.

How do I set the y axis values in R?

To change the axis scales on a plot in base R Language, we can use the xlim() and ylim() functions. The xlim() and ylim() functions are convenience functions that set the limit of the x-axis and y-axis respectively.


1 Answers

b0 = 2.5; b1 = 2
n = 100
x = rnorm(n, 20, 15)
y = b0 + b1*x + rnorm(n, 0, 15)
plot(x, y)
plot(x, y, type='n')
text(x, y, round(y, 2), cex=0.45)
text(x, y, round(y, 2), cex=0.8)
text(x, y, paste(round(x, 2), round(y, 2), sep=", "), cex=0.8) # for (x, y), but this gets cluttered. 

alt text

Use cex for character size (see help for text). And use plot(x, y, type='n') to set up your window correctly without actually plotting anything.

like image 139
Vince Avatar answered Oct 16 '22 12:10

Vince