Martz Martz - 1 year ago 110
R Question

boxplots with missing values in R - ggplot

I am trying to make boxplots for a matrix (athTp) with 6 variables (columns) but with many missing values, '


But maybe sth I am doing wrong...

I tried also to make many box plots and after to arrange the grid, but the final plot was very small (in desired dimensions), loosing many of details.

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

..continue with other 5 columns

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

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

Do you have any ideas?
Thanks in advance!

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

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

# 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()`]
ggplot(longdat, aes(x=variable, y=value)) + geom_boxplot(aes(colour = variable))

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download