Context
I want to show a specific value at x axis in ggplot2. It is 2.84
in the Reproducible code.
CodePudding user response:
You can automate this process by creating a wrapper round scale_x_continuous
that inserts your break into a vector of pretty
breaks:
scale_x_fancy <- function(xval, ...) {
scale_x_continuous(breaks = ~ sort(c(pretty(.x, 10), xval)), ...)
}
So now you just add the x value(s) where you want the extra break to appear:
ggplot(d, aes(x, y))
geom_point()
theme_minimal()
scale_x_fancy(xval = 2.84, name = "Number of treatments")