As suggested by @Roland, you can add text to your plot using geom_text
or geom_label
or annotate
. Here is the code using geom_text
:
data <- structure(list(n = c(100000L, 200000L, 300000L, 400000L, 500000L
), value = c(20L, 30L, 25L, 40L, 12L)), .Names = c("n", "value"
), class = "data.frame", row.names = c(NA, -5L))
library(ggplot2)
ggplot(data, aes(x=n, y=value)) +
geom_point(aes(n,value)) + geom_line(aes(n,value))+
geom_text(aes(label=value), hjust=c(-1,0,0,-1,2), vjust=c(1,-.5,1.5,0,0))

hjust
controls horizontal justification and vjust
controls vertical justification. Details are given at this link. Using geom_label
ggplot(data, aes(x=n, y=value)) +
geom_point(aes(n,value)) + geom_line(aes(n,value))+
geom_label(aes(label=value), hjust=c(-1,0,0,-1,2), vjust=c(1,-.5,1.5,0,0))
the result is:

It is also possible to use annotate
as follows:
ggplot(data, aes(x=n, y=value)) +
geom_point(aes(n,value)) + geom_line(aes(n,value))+
annotate("text", x=data$n, y=data$value, label=data$value,
hjust=c(-1,0,0,-1,2), vjust=c(1,-.5,1.5,0,0))
