Plot with inverted y-axis and x-axis on top in ggplot2
I'm trying to get ggplot2
with the Y-axis inverted and the X-axis on top. I used scale_y_reverse()
to get the inverse Y-axis, but couldn't figure out how to put the X-axis on top instead of bottom.
dfn <- read.table(header=T, text='
supp dose length
OJ 0.5 13.23
OJ 1.0 22.70
OJ 2.0 26.06
VC 0.5 7.98
VC 1.0 16.77
VC 2.0 26.14
')
library(ggplot2)
p1 <- ggplot(data=dfn, aes(x=dose, y=length, group=supp, colour=supp)) + geom_line() + geom_point()
p1 <- p1 + scale_y_reverse()
print(p1)
+4
source to share
3 answers
If you don't want to switch to ggvis yet, the ggdraw(switch_axis_position(p1 , axis = 'x'))
package feature cowplot
works really well.
https://cran.r-project.org/web/packages/cowplot/vignettes/axis_position.html
+4
source to share