在我的真实研究世界中,在顶部(或顶部和底部)显示 x 轴,在右侧显示 y 轴是很常见的。但是,ggplot2 中的默认位置是底部的 x 和左侧的 y。
关注 Kohske Post Here ,使用的命令是:
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"))
我在开发模式下尝试了上述命令:
install_packages("devtools")
library(devtools)
dev_mode()
install_github("ggplot2", "kohske", "feature/pguide")
library(ggplot2)
不幸的是,它不适用于最新的
plyr
包裹。留言: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)
然后我尝试了codes from github直接发送的消息是:
Error in continuous_scale(c("x", "xmin", "xmax", "xend", "xintercept"), :
formal argument "guide" matched by multiple actual arguments
我注意到 Hadley 说这个功能在他的待办事项 list 上。但是,此时我找不到解决方案。有人可以帮忙吗?
最佳答案
来自 ggplot 2.2.0
您可以使用 position
设置轴的位置参数在 scale_
:
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
scale_x_continuous(position = "top") +
scale_y_continuous(position = "right")
关于r - 如何更改 ggplot2 中 x 和 y 轴的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15334494/