繁体   English   中英

当 y 轴在右侧时调整 y 轴标题和文本之间的边距(ggplot2)

[英]Adjusting margins between y-axis title and text when y-axis is on the right (ggplot2)

第一次发帖,很抱歉我错过了任何形式。 当 y 轴位于图表的右侧时,我正在尝试调整 y 轴标题和文本之间的边距。 在 'element_text' 中使用 'margin = ' 似乎仅在 y 轴位于左侧时才有效。 以下是一些示例数据:

dat <- data.frame(x = rnorm(10), y = rnorm(10)) 

plot.y.left <- ggplot(data = dat, aes(x = x, y = y))+
  geom_point()+
  theme(axis.title.y = element_text(margin = unit(c(0, 20, 0, 0), 'mm')))
plot.y.left

plot.y.right <- ggplot(data = dat, aes(x = x, y = y))+
  geom_point() +
  scale_y_continuous(position = "right") +
  theme(axis.title.y = element_text(margin = unit(c(0, 0, 0, 20), 'mm')))
plot.y.right  

我已经尝试将 20 放在不同的arguments虽然我知道它不会运行, r,下,左),但不管你把“20”放在哪里,边距总是固定在同样的 position。 有谁知道如何解决这个问题?

提前感谢您的帮助

干杯,

您可以在主题中使用axis.title.y.right

plot.y.right <- ggplot(data = dat, aes(x = x, y = y))+
  geom_point() +
  scale_y_continuous(position = "right") +
  theme(axis.title.y.right = element_text(margin = unit(c(0, 0, 0, 20), 'mm')))

plot.y.right  

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM