ggplot2 图表绘制报错: 缺少逗号导致代码无法运行
ggplot2 图表绘制报错: 缺少逗号导致代码无法运行
报错原因: 代码中缺少一个逗号,导致代码无法运行。
解决办法: 在 remove_y 中添加逗号,即将 remove_y 修改为如下代码:
remove_y <- theme(
axis.text.y = element_blank(),
axis.ticks.length.y = element_blank(),
axis.title.y = element_blank(),
)
示例代码:
p1 <-ggplot(dataA,aes(cancer,exp,fill=cancer))+
geom_violin()+
coord_flip()+
scale_fill_manual(values = colors)+
stat_summary(fun=mean,geom = 'point',
shape = 19, size = 2, color = 'black')+
theme_bw()+
geom_hline(aes(yintercept=0.6),colour='#565354',linetype='dashed')+
geom_hline(aes(yintercept=0.3),colour='#565354',linetype='dashed')+
xlab('')+
ylab('A indicator
indicator A')+
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.text.y = element_text(size = 12,
face = 'bold'),
legend.title = element_blank(),
legend.position = 'none')
p1
remove_y <- theme(
axis.text.y = element_blank(),
axis.ticks.length.y = element_blank(),
axis.title.y = element_blank(),
)
p <- list(
p1,
p1 + remove_y,
p1+remove_y,
p1+remove_y
)
library(patchwork)
wrap_plots(p, nrow=1)
注意:
- 此错误通常发生在使用
theme()函数创建自定义主题时。 - 添加逗号后,代码应该可以正常运行。
- 确保代码中没有其他错误。
原文地址: https://www.cveoy.top/t/topic/nJV2 著作权归作者所有。请勿转载和采集!