R 中缺失值的箱线图 - ggplot

boxplots with missing values in R - ggplot

我正在尝试为具有 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")

你有什么想法吗? 提前致谢!

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