因子(变量)错误:找不到对象“变量”

时间:2018-08-15 18:26:04

标签: r ggplot2

实际上,我对R软件还很陌生(当前使用R 3.5.0),并且最近在尝试创建森林图时遇到错误消息。对于此问题的潜在解决方案,我将不胜感激。

同样,错误消息指出:因子(变量)错误:找不到对象“变量”。

另外,请在下面找到我使用的代码。

Z.test <- read.csv(file = "C://Users//yli33//Desktop//Figure_CDCR.csv", sep=",", header=TRUE)

dummy2 <- data.frame(X = c("90th vs 50th"), Z = 0)

Z.test$MeAT <- factor(Z.test$MeAT, levels = c("1"), labels=c("A. 90th vs 50th"))

Z <- ggplot(Z.test, aes(factor(variable), Risk)) +
geom_point(shape=21, size=3, fill="blue") +
geom_errorbar(width=.05, aes(ymin=lower, ymax=upper)) +
facet_wrap(~ MeAT, ncol = 3, scales = "fixed")

Z + scale_x_discrete(breaks=c(1,2,3,4,5,6,7,8,9) , labels=c("C_others","C_others_M","C_others_F","C_migrant","C_migrant_M","C_migrant_F","C_seasonal","C_seasonal_M","C_seasonal_F"))+
labs (x = "Patient characteristics", y = "Percent change in risk of clinic visit") +
theme(panel.background = element_rect(fill = 'white', colour = 'black'))+
theme(axis.title.y = element_text(2,2,size=10), axis.title.x = element_text(2,2,size=10),
axis.text.x  = element_text(angle=0, vjust=0.7, size=8, color='black'),
axis.text.y  = element_text(angle=0, vjust=0.7, size=7,color='black'),
panel.grid.major.x = element_blank(),panel.grid.minor.y = element_blank(),
panel.grid.major.y = element_line( size=.1, color="white" )) +
geom_hline(data = dummy2, aes(yintercept = Z), colour="#990000", linetype="dashed")

谢谢!

0 个答案:

没有答案