[英]R: ggarrange() "No graphics to replay" error
我正在使用 ggarrange() 组合 3 个 ggplots 并收到以下错误消息:
"In grid.echo.recordedplot(dl, newpage, prefix) : No graphics to replay"
我的其中一个图的代码(它们都是相同的只是不同的值)和 ggarrange() 如下:
All_data_80<-All_data[All_data$rh.x == "80H",]
All_data_80<-All_data[All_data$rh_std_num == "80",]
All_data_80<-na.omit(All_data_80)
plot_80<-ggplot
ggplot(data=All_data_80 , aes(x = `Name`, y=`q`, fill=`Name`)) +
theme_bw()+
ggtitle("Plot Title")+
geom_col(data=All_data_80[All_data_80$Number=="5",],position=position_dodge(width=0.5))+
geom_col(data=All_data_80[All_data_80$Number=="14",],position=position_dodge(width=0.5))+
geom_col(data=All_data_80[All_data_80$Number==="95",],position=position_dodge(width=0.5))+
xlab("Name")+
ylab("Percentage")+
theme(axis.text.x = element_blank(),
axis.text.y = element_text(size=8),
legend.text=element_text(size=12),
legend.title=element_blank(),
legend.position = "bottom",
axis.title=element_text(size=12,hjust = 0.5),
plot.title = element_text(face="bold",size=14, hjust = 0.5),
plot.caption=element_text(size=12,hjust = 0.0),
strip.text = element_text(size=12),
panel.grid.major = element_blank())
plot_80
ggarrange(plot_40, plot_60, plot_80, labels=c("A","B","C"), nrow=1, ncol=3)
谁能帮我理解我哪里出错了? 谢谢!
回答
您永远不会在plot_40
、 plot_60
或plot_80
中存储任何图,因此 plot 没有任何内容。 您将实际的ggplot
function 存储在其中。
可重现的例子
test <- ggplot2::ggplot
ggpubr::ggarrange(test)
这产生:
Warning message:
In grid.echo.recordedplot(dl, newpage, prefix) : No graphics to replay
推理
在您的代码中,出现这种情况是因为您写道:
plot_80 <- ggplot
*ggplot call*
plot_80
因此,您将ggplot
function 存储在plot_80
中,然后您将 output 存储在 plot 中(但从不存储它),然后调用plot_80
(但从不存储它)的内容我想你的意思是把它写成:
plot_80 <- *ggplot call*
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.