做龙卷风图时,运行代码,报了warning,无法显示图。
图的代码
library(RColorBrewer)
mycolors<-brewer.pal(4,"Set1")
options(scipen = 200)
p<- plot(res_dsa, type = "difference",result = "icer",remove_ns = TRUE,
resolve_labels = TRUE,limits_by_bars = FALSE,shorten_labels = TRUE)+
scale_color_manual(values = mycolors[c(1,3,2,2)]) + #自定义颜色
theme_classic()+
# scale_x_continuous(breaks=seq(-300000, 700000, 100000))+
geom_vline(aes(xintercept=-23013.864),color="black")+
# geom_vline(aes(xintercept=100000),color=mycolors[3],linetype = "dashed")+
geom_vline(aes(xintercept=150000),color=mycolors[3],linetype = "dashed")+
ggtitle("Tornado Diagrams of Univariable Sensitivity Analyses")+
xlab("ICER, $/QALY") +
theme(
axis.text.x=element_text(),
strip.placement = "outside",
strip.background = element_rect(),
plot.title = element_text(family='Times', face='bold.italic',size = 22),
axis.text = element_text(color = "black",size = 12),
axis.title.x = element_text(family = 'Times',face = 'bold',size =15),
axis.title.y = element_text(family = 'Times',face = 'bold',size=10),
)
p
pdf(file = "Tornado Diagrams.pdf",width = 10,height = 6)
p
然后是warning提示:
Warning messages:
1: Removed 96 rows containing missing values (geom_vline()
).
2: Removed 96 rows containing missing values (geom_vline()
).
方案来自 梦想橡皮擦 狂飙组基于 GPT 编写的 “程秘”
这个warning消息是指你在绘制图中使用了geom_vline()函数时,发现有96行数据存在缺失值,因此它们被删除了。
在绘制龙卷风图时,你需要确保所有的数据都是完整的。如果有任何缺失的数据,请考虑替换或删除这些数据。
关于geom_vline()函数,它用于在图中添加一条垂直线,你可以指定线的横坐标,并使用颜色和线型等参数进行标记。在你的代码中,你使用了三次该函数,分别为:
geom_vline(aes(xintercept=-23013.864),color="black")
geom_vline(aes(xintercept=150000),color=mycolors[3],linetype = "dashed")
如果你在绘制图的过程中一直收到此warning,请检查数据是否完整,以确保最终的结果是准确的。
以下答案引用自GPT-3大模型,请合理使用:这两条warning信息是因为使用了geom_vline()函数,在数据集中有较多的缺失值导致的。要解决这个问题,可以尝试更新数据集,或者使用其他的函数来表示线。