我已经在绘图中添加了辅助y轴(使用ggplot2),并设法在该轴上获得了比例尺。但是,我的主要y轴上的比例现在已还原为默认值,而不是我设置的默认值。
我还想将副轴上的标题的格式设置为与我的另两个轴之间的距离相同,而不是紧邻轴标签。
最后,我想要一个键,只是要说出线条和线条所显示的内容。
这是我的数据:
Month Average Methane Flux Standard Error CH4 flux Average Air temperature
Aug -967.19 1725.28 19.58
Sep 1428.95 718.88 19.17
Oct 1275.80 2968.65 12.70
Nov
Dec
Jan
Feb
Mar
Apr
May
Jun
Jul
代码:
Month1 <- factor(Month, levels=unique(as.character(Month)))
p <- ggplot(data = Elstow.monthly.fluxes,
aes(x = Month1, y = Average.Methane.Flux)) +
geom_bar(stat = "identity", colour = "black") +
geom_errorbar(aes(ymin = Average.Methane.Flux - Standard.Error.CH4.flux,
ymax = Average.Methane.Flux + Standard.Error.CH4.flux,
width = 0.4)) +
geom_line(data = Elstow.monthly.fluxes,
aes(Month1, Average.Air.temperature*100, group = 1),
colour = "Red", size = 1) +
xlab(expression("Month")) +
ylab(expression(Average~CH[4]~Flux~(µg~CH[4]~m^{-2}~d^{-1}))) +
scale_y_continuous(breaks = seq(-3000,4500,500)) +
scale_y_continuous(sec.axis = sec_axis(~./100,
name = "Average Air Temperature (°C)",
breaks = seq(-25,45,5))) +
theme(axis.text.x = element_text(colour = "black")) +
theme(axis.text.y = element_text(colour = "black")) +
theme(panel.background = element_rect("white", "black")) +
theme(panel.border = element_rect(colour = "black", fill=NA, size=0.5)) +
theme(axis.text = element_text(size = 12))+
theme(axis.title = element_text(size = 14))+
theme(axis.title.y = element_text(margin = margin(t = 0, r = 10, b = 0, l = 0))) +
theme(axis.title.x = element_text(margin = margin(t = 10, r = 0, b = 0, l = 0)))
print(p)