2016-11-10 44 views
0

我試圖做箱線的矩陣(athTp)與6個變量(列)但有許多遺漏值,「箱圖與R中遺漏值 - ggplot

ggplot(athTp)+geom_boxplot() 

但也許......我做錯了...

我也試圖製作很多盒子圖和後來安排網格,但最後的情節是非常小的(在所需的尺寸),失去了許多細節。

q1 <- ggplot(athTp,aes(x="V1", y=athTp[,1]))+ geom_boxplot() 

..continue與其他5列

grid.arrange(q1,q2,q3,q4,q5,q6, ncol=6) 

ggsave("plot.pdf",plot = qq, width = 8, height = 8, units = "cm") 

你有什麼想法? 在此先感謝!

回答

0
# ok so your data has 6 columns like this 
set.seed(666) 
dat <- data.frame(matrix(runif(60,1,20),ncol=6)) 
names(dat) <- letters[1:6] 
head(dat) 

# so let's get in long format like ggplot likes 
library(reshape2) 
longdat <- melt(dat) 
head(longdat) 

# and try your plot call again specifying that we want a box plot per column 
# which is now indicated by the "variable" column 
# [remember you should specify the x and y axes with `aes()`] 
library(ggplot2) 
ggplot(longdat, aes(x=variable, y=value)) + geom_boxplot(aes(colour = variable)) 

enter image description here

+0

..所以 「長格式」 這是問題!非常感謝,它現在起作用! – Marz