我正在尝试为6个变量(列)但有许多缺失值的矩阵(athTp)制作箱图,'
ggplot(athTp)+geom_boxplot()
但也许......我做错了......
我还尝试制作许多箱形图,然后安排网格,但最终的情节非常小(在所需尺寸上),丢失了许多细节。
q1 <- ggplot(athTp,aes(x="V1", y=athTp[,1]))+ geom_boxplot()
..继续其他5列
grid.arrange(q1,q2,q3,q4,q5,q6, ncol=6)
ggsave("plot.pdf",plot = qq, width = 8, height = 8, units = "cm")
你有什么想法吗? 提前谢谢!
答案 0 :(得分: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))