2017-01-08 11 views
0

いくつかの奇妙な理由により、textコマンドですべての単語が表示されない。ここに私の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)); 

それはなぜ額面(mfrowの=のC(5,2))理由ですので、これらの8つのより多くのプロットがあり、このように符号化されます。しかし何らかの理由ですべての文字が表示されているわけではありません。私にはバグのようです。

これを修正する方法はありますか?

+0

あなたは多くのパッケージをインポートしています。彼らは実際にこの例を示す必要がありますか? –

+0

私の悪いです。不要なパッケージを削除しました – Mark

+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)) 

enter image description here

あなたは、いくつかのプロットを持っている場合は、一つの方法は、grid.arrangeを(いくつかの調整が依然として必要)を使用して、それらを組み合わせることです。

library(gridExtra) 
grid.arrange(p1, p1, p1, p1, ncol = 2) 

enter image description here

関連する問題