I want to create a new axis for an existing plot. I can use the geom_line
layer for this but how do I add labels for X and Y axis (similar to the default axis).
One option would be ggh4x::coord_axes_inside
which offers an out-of-box option to add inside axes:
library(ggplot2)
library(ggh4x)
iris |>
ggplot(aes(Sepal.Length, Sepal.Width, color = Species)) +
geom_point() +
theme(axis.line = element_line()) +
coord_axes_inside(
labels_inside = TRUE,
xintercept = 6,
yintercept = 3
)