The development version of ggplot2 (2.1.0.9001) provides a nice shorthand for creating a secondary axis that is a duplication of the primary axis if the original axis i
The switch_axis_position is now deprecated, and in fact is gone. Issues with ggdraw since ggplot2 update
Outdated material:
The cowplot library has used to have that that facility:
library(cowplot)
gpv <- ggplot(mpg, aes(displ, factor(cyl))) +
geom_point()
ggdraw( switch_axis_position( gpv, axis="y", keep="y"))
Don't forget that you need to print
grid-based graphics when sending to a file:
png()
print(ggdraw(switch_axis_position(gpv, axis="y", keep="y")) )
dev.off()
#quartz
# 2