Reputation:
How do I make a geom_hline
not to be shown across the entire plot?
d=data.frame(x=c(1,2,3,4,4,6,7,9), y=c(9,3,7,1,8,4,5,6))
ggplot() +
geom_point(data=d, mapping=aes(x=x, y=y)) +
geom_hline(yintercept=5.375, color="red")
Produces:
How do I let geom_hline
go from, for example, 2.6 until 4.2?
Upvotes: 2
Views: 880
Reputation: 1553
You can use geom_segment:
d=data.frame(x=c(1,2,3,4,4,6,7,9), y=c(9,3,7,1,8,4,5,6))
ggplot() +
geom_point(data=d, mapping=aes(x=x, y=y)) +
geom_segment(aes(x=2,xend=4.2,y=5.375,yend=5.375),color="red")
Upvotes: 3