我并排绘制了两个具有相同 y 轴刻度的图,并使用cowplot 对齐它们。我想删除右侧图的 y 轴,但是当我这样做时,这个图变得比左边的更宽(我希望这些图的大小相同)。有谁知道我如何删除正确图的 y 轴但保持两个图的大小相同?任何帮助将非常感激。由于数据的性质,我不能使用分面。我无法分享实际数据,也不知道如何模拟任何数据,但我希望这个问题不需要,并且我已经尽可能多地分享了代码。如果可能的话,我也想坚持使用cowplot。谢谢你。
#code with y axis on both
library(ggplot2)
library(cowplot)
p1<-ggplot(clins, aes(x = Clinician, y = slope, ymin = slope - 2 * se, ymax = slope + 2 * se)) + geom_point(color="blue") + geom_errorbar(colour="blue") + scale_y_continuous(limits=c(-0.16,1), breaks=c(-0.16, 0.00, 0.25, 0.50, 0.75, 1.00), labels=c("", "0.00", "0.25", "0.50", "0.75", "1.00"), expand=c(0,0)) + theme(axis.ticks.y=element_line(colour=c("transparent", "black", "black", "black", "black", "black")), panel.border=element_rect(colour="black", fill=NA), text=element_text(family="Times New Roman", face="bold", size=12), panel.background=element_rect(fill="white"), panel.grid.major.x=element_blank(), panel.grid.major.y=element_line(size=.1, colour="black",linetype="dotted"), plot.title=element_text(hjust=0.5), axis.text.x=element_text(colour="black", angle=60, hjust=1), axis.text.y=element_text(colour="black")) + labs(y= "Slope")
p2<-ggplot(vigns, aes(x = Vignette, y = slope, ymin = slope - 2 * se, ymax = slope + 2 * se)) + geom_point(colour="red") + geom_errorbar(colour="red") + scale_y_continuous(limits=c(-0.16,1), breaks=c(-0.16, 0.00, 0.25, 0.50, 0.75, 1.00), labels=c("", "0.00", "0.25", "0.50", "0.75", "1.00"), expand=c(0,0)) + theme(axis.ticks.y=element_line(colour=c("transparent", "black", "black", "black", "black", "black")), panel.border=element_rect(colour="black", fill=NA), text=element_text(family="Times New Roman", face="bold", size=12), panel.background=element_rect(fill="white"), panel.grid.major.x=element_blank(), panel.grid.major.y=element_line(size=.1, colour="black",linetype="dotted"), plot.title=element_text(hjust=0.5), axis.text.x=element_text(colour="black", angle=20, hjust=1), axis.text.y=element_text(colour="black")) + labs(y= "Slope")
plot1<- plot_grid(p1, p2, align = 'h')
title<- ggdraw() + draw_label("Slope Coefficients by Clinician and Vignette", fontface='bold', fontfamily='Times New Roman')
svg("Plot1.svg",width=10,height=4.00)
plot_grid(title, plot1, ncol=1, rel_heights=c(0.1,1))
dev.off()
#code with y axis removed for second plot
p3<-ggplot(vigns, aes(x = Vignette, y = slope, ymin = slope - 2 * se, ymax = slope + 2 * se)) + geom_point(colour="red") + geom_errorbar(colour="red", width=.15) + scale_y_continuous(limits=c(-0.16,1), breaks=c(-0.16, 0.00, 0.25, 0.50, 0.75, 1.00), labels=c("", "0.00", "0.25", "0.50", "0.75", "1.00"), expand=c(0,0)) + scale_x_discrete(expand=c(0,0)) + theme(axis.title.y=element_blank(), axis.text.y=element_blank(), axis.ticks.y=element_blank(), panel.border=element_rect(colour="black", fill=NA), text=element_text(family="Times New Roman", face="bold", size=12), panel.background=element_rect(fill="white"), panel.grid.major.x=element_blank(), panel.grid.major.y=element_line(size=.1, colour="black",linetype="dotted"), plot.title=element_text(hjust=0.5), axis.text.x=element_text(colour="black", angle=45, hjust=1))
plot2<- plot_grid(p1, p3, align = 'h')
title<- ggdraw() + draw_label("Slope Coefficients by Clinician and Vignette", fontface='bold', fontfamily='Times New Roman')
svg("Plot2.svg",width=10,height=4.00)
plot_grid(title, plot2, ncol=1, rel_heights=c(0.1,1))
dev.off()