Polisetty
Polisetty

Reputation: 125

How to annotate a graph with corresponding x and y axis values - ggplot2?

I have a sigmoid curve and want to annotate the 50% using ggplot2 as shown in the image below in dotted red. I know how to add a line to the graph but that goes all the way to the top. I want the lines coming from x and y-axis and reach and stop at that point.

enter image description here

Upvotes: 1

Views: 352

Answers (1)

myincas
myincas

Reputation: 1530

You can use geom_segment.

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) +
  geom_point() +
  geom_segment(x = 0, xend = 6, y = 3, yend = 3, linetype = 2, color = 'red3') +
  geom_segment(x = 6, xend = 6, y = 0, yend = 3, linetype = 2, color = 'red3') 

enter image description here

Upvotes: 1

Related Questions