Reputation: 7622
I had a graph created with default R-plot functionality but now want to change to ggplot2 mainly because I want to use ggrepel to place labels correctly and non-overlapping.
My old plot contains diagonal lines which I need to keep. They are ploted like this:
for (i in -5:10) {
abline(a= i, b= 1, lty = 5)
}
The issues I have now are:
How do I do this for-loop with ggplot2 so I don't need to add all the lines expliclty?
How do I actually created the lines correctly?
geom_abline(slope=1, intercept=10)
Does not work as expected, probably due to log10 scale. So how can I draw diagonal lines on log10 scales correctly?
Upvotes: 1
Views: 1285
Reputation: 7622
It actually works fine. This issue is directly related to my other issue about x and y axis limits. Per default the plot draws a bigger area than the x and y limits define (who thought this was a good idea???). And therefore the intercepts look wrong but the actually are ok.
If I set expand = c(0, 0)
for both axis, then the intercept is also looks fine because that only draws to the limits.
The solution for multiple lines is a intercept list:
geom_abline(slope=1, intercept=(-3):(5)
Upvotes: 1