How to change positions of x and y axis in ggplot2
ggplot2, r
Solution
From `ggplot 2.2.0` you can set the position of the axes with the `position` argument in `scale_`:
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
scale_x_continuous(position = "top") +
scale_y_continuous(position = "right")
Problem
In my real research world, it is very common to show x-axis on the top (or both top and bottom) and y-axis on the right. However, the default positions are x on the bottom and y on the left in ggplot2. Following Kohske Post Here, the commands used are: ``` x <- seq(0, 10, 0.1) y <- sin(x * pi) qplot(x, y, geom = "line") + scale_x_continuous(guide = guide_axis(position = "top")) + scale_y_continuous(guide = guide_axis(position = "right")) ``` I have tried above commands in dev-mode: ``` install_packages("devtools") library(devtools) dev_mode() install_github("ggplot2", "kohske", "feature/pguide") library(ggplot2) ``` Unfortunately, it didn't work well with the latest `plyr` package. Messages: ``` The following 'from' values not present in 'x': col, color, pch, cex, lty, lwd, srt, adj, bg, fg, min, max... Error in plyr:::split_indices(seq_len(nrow(data)), scale_id, n) ``` Then I tried the codes from github directedly, the messages are: ``` Error in continuous_scale(c("x", "xmin", "xmax", "xend", "xintercept"), : formal argument "guide" matched by multiple actual arguments ``` I have noticed that Hadley said this functionality is on his to-do list. However, I could not find a solution at this moment. Could anyone help?