I created a function to create barchart with ggplot.
In my figure, I want to overlay a graph with white horizontal stripes in the position of the labels, as in the figure below
p <- ggplot(iris, aes(x = Species, y = Sepal.Width)) +
geom_bar(stat = 'identity')
p + geom_hline(aes(yintercept = seq(50,150,50)), colour = 'white')

However, I would like to be able to modify the data, so I cannot use static positions for strings, as in the example. For example, I can change Sepal.Withto Sepal.Heightin the above example.
Can you tell me how:
- get tick positions from my ggplot; or
- get the function that
ggplotuses for the tick position so that I can use it to place my lines.
so i can do something like
tickpositions <- ggplot_tickpostion_fun(iris$Sepal.Width)
p + scale_y_continuous(breaks = tickpositions) +
geom_hline(aes(yintercept = tickpositions), colour = 'white')
source
share