79727357

Date: 2025-08-06 13:38:24
Score: 1.5
Natty:
Report link

Answer based on the comment of @jon-spring and ggplot2 documentation:

You can duplicate the x-axis by defining a secondary x-axis in the scale_x_* call. For example: scale_x_continuous(sec.axis = dup_axis())

The breaks, labels, and title of the duplicated axis can be formatted via dup_axis() arguments.

Using the iris dataset:

library(ggplot2)
ggplot(iris, aes(Sepal.Length, Sepal.Width)) +
    geom_point() +
    scale_x_continuous(sec.axis = dup_axis(name="example title", breaks=c(5, 5.5, 6)))

iris dataset example of secondary x-axis

The same procedure is possible also for y-axis.

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @jon-spring
  • Low reputation (0.5):
Posted by: ppoyk