增大次要y轴与其标题之间的间隔

问题描述 投票:0回答:1

我已经绘制了一个带有两个y轴的图形。但是,对于我来说,轴的标题离它们太近了。我设法使主轴标题保持距离,但无法弄清楚如何对辅助轴执行相同的操作。这是我使用的代码:

ggplot(data1, aes(x=year))+
geom_line(aes(y= data1$`export share`, colour= "export share"), size = 2)+
  geom_line(aes(y=data1$pm25/coeff, colour= "pm25"), size = 2)+
  scale_x_continuous(breaks = scales::pretty_breaks(n = 17), name = "Year")+
  scale_y_continuous(name="Export Share of GDP", labels = scales::percent, sec.axis=sec_axis(trans = ~.*coeff, name = "PM2.5"))+
  theme(axis.title.y = element_text(margin = margin(t = 0, r = 20, b = 0, l = 0)), axis.text.x = element_text(vjust = 5) ,legend.title = element_blank(), legend.box.margin = margin(0,0,0,10), text = element_text(size = 30)) +
  scale_colour_discrete("",
                        breaks=c("export share", "pm25"),
                        labels=c("Export Share of GDP", "PM2.5")) +
  geom_vline(xintercept=2006) +
   geom_vline(xintercept = 2000)

“这是图形的图片”

r ggplot2 axis-labels yaxis
1个回答
0
投票

您可以通过增加plot.margin的第二个参数来增加右边距。

+ theme(plot.margin=unit(c(1,3,1,1), "cm"))

然后增加vjustaxis.title.y.right参数:

+ theme(axis.title.y.right = element_text(vjust=2 or 3 or 4))

vjust的较大数字离轴更远。当然,您可以将以上两个“主题”命令组合为一个。

© www.soinside.com 2019 - 2024. All rights reserved.