The x and y axis are labeled based on certain interval set by ggplot.
In the event that a horizontal or vertical line is added to the plot, the goal is to label x or y axis at the exact value of the line.
How can this be done?
The x and y axis are labeled based on certain interval set by ggplot.
In the event that a horizontal or vertical line is added to the plot, the goal is to label x or y axis at the exact value of the line.
How can this be done?
This isn't totally straightforward, but it is possible. I would probably use these two little functions to automate the tricky parts:
These would work like this. Start with a basic plot:
Add a vertical line with
add_x_breakAdd a horizontal line with
add_y_break:ADDENDUM
If for some reason you do not have the code that generated the plot, or the vline is already present, you could use the following function to extract the xintercept and add it to the axis breaks:
So, for example:
Then we can do:
The y intercepts of
geom_hlinecan be obtained in a similar way, which should hopefully be evident from the code ofadd_x_intercepts