I have a horizontal line in a ggplot and I would like to label it's value (7.1) on the y axis.
library(ggplot2)
df <- data.frame(y=c(1:10),x=c(1:10))
h <- 7.1
plot1 <- ggplot(df, aes(x=x,y=y)) + geom_point()
plot2 <- plot1+ geom_hline(aes(yintercept=h))
Thank you for your help.
Best Answer
It's not clear if you want 7.1 to be part of the y-axis, or if you just want a way to label the line. Assuming the former, you can use
scale_y_continuous()
to define your own breaks. Something like this may do what you want (will need some fiddling most likely):Assuming the latter, this is probably more what you want: