EcologyTom EcologyTom - 2 months ago 14x
R Question

Multiple geom_hline in ggplot

I would like to include two horizontal lines using geom_hline in ggplot. The scale on my graph runs from 0 to 20,000 and I would like to have single lines at 400 and 17,000.

gives examples for single lines (
geom_hline(yintercept = 20)
) and for multiple lines (
(geom_hline(yintercept = 1:5)
). But the latter will give a line at every point between the two numbers.

geom_hline(yintercept = 400: 17000)
creates lines with intercepts at
400, 401, 402
etc. And
geom_hline(yintercept = 400, 17000)
only produces a single line for the first number. I'm sure there's something apart from
I need to try, does anyone have any suggestions?


I simulated some rnorm x<-rnorm(500); d<-data.frame("x"=x,"den"=dnorm(x)) and plot them as a line, it works your data in data.frame?

Does this work for you if you simulate the values?

ggplot(d,aes(x,den))+geom_line()+geom_hline(yintercept = c(0.1,0.2))