由于某些奇怪的原因,文本命令不会显示所有单词。这是我的df和代码:
library(reshape)
library(coda)
install.packages("coefplot2",
repos="http://www.math.mcmaster.ca/bolker/R",
type="source") #modified
library(coefplot2)
predictor <- c("X1", "X2", "X3", "X4", "X5")
coef <- c(0.0000000, -0.2253459, -0.7849048, -0.9388088, -1.1509515)
CI <- c(0.0000000, -0.8570941, -0.6416209, -0.6990803, -0.6287817)
df <- data.frame(predictor, coef, CI)
df$predictor <- as.character(droplevels(df$predictor))
par(mfrow = c(5,2))
coefplot2(df[, 3], df[, 2], varnames= df[,2], CI=1,h.axis=F
, xlim=c(-3.5, 1.5), main="", mar=c(1,6,2,1), cex.var=1, cex.pts=1.5, pch.pts=16, lwd.2=1, frame.plot=T)
mtext(expression(paste(bold("X"))),cex=0.8, adj=0,line = 2.3)
text(-3.65,5,"E",cex=0.8,adj = c(0,0.6));
text(-3.65,4,"BE",cex=0.8,adj = c(0,0.6));
text(-3.65,3,"BC",cex=0.8,adj = c(0,0.6));
text(-3.65,2,"AC",cex=0.8,adj = c(0,0.6));
text(-3.65,1,"A",cex=0.8,adj = c(0,0.6));
还有8个这样的图,这就是par(mfrow = c(5,2))以这种方式编码的原因。但由于某种原因,不是所有的字母都显示出来..看起来像是一个错误。
任何想法如何解决这个问题?
答案 0 :(得分:0)
我发现ggplot2
更适合展示结果。
library(ggplot2)
sds <- 1
text.add <- data.frame(text = c("E", "BE", "BC", "AC", "A"), y = c(-3.6), x = 5:1)
(p1 <- ggplot(df, aes(x = predictor, y = coef)) +
theme_bw() +
geom_pointrange(aes(ymin = coef - sds * CI, ymax = coef + sds * CI)) + # adds CIs
scale_x_discrete(labels = df$coef) + # sets vertical labels
geom_text(data = text.add, aes(x = x, y = y, label = text)) + # adds text to the left side
theme(axis.text.x = element_blank(), axis.title.x = element_blank(), # clears x axis
axis.ticks.x = element_blank()) +
coord_flip() # flips everything
ggsave("onefig.png", width = 4, height = 2))
如果你有几个图,一种方法是使用grid.arrange
组合它们(仍需要一些调整)。
library(gridExtra)
grid.arrange(p1, p1, p1, p1, ncol = 2)