r - Adding several box plots in one -



r - Adding several box plots in one -

i have dataset have 3 different groups of individuals, let´s phone call them green, red, , blue. have info covering 92 proteins in blood, have readings each individual in each group.

i overview of variances , means each protein each group. means create multiple box plot graph.

i have different proteins on x-axis, , 3 box plots (preferably in different colors) (one each group) above every protein, numeric protein weight on y-axis.

how do this?

i working info frame groups divided rows, , different protein readings in each column.

tried add together picture, apparently need reputation-points…

i´ve heard can utilize melt command in reshape2, need guidance in how utilize it.

please, simplify answers. i´m not experienced when comes r.

look, realize things frustrating when first getting started, you're going have inquire specific , targeted questions people willing , able help out in structured way.

having said that, let's walk through structured example. going utilize 9 proteins here, should idea.

library(ggplot2) library(reshape2) # setup info frame, since question did not provide one... df <- structure(list(individual = 1:12, grouping = structure(c(2l, 1l, 3l, 2l, 1l, 3l, 2l, 1l, 3l, 2l, 1l, 3l), .label = c("blue", "green", "red"), class = "factor"), protein_1 = c(82l, 23l, 19l, 100l, 33l, 86l, 32l, 41l, 39l, 59l, 93l, 99l), protein_2 = c(86l, 50l, 86l, 90l, 37l, 20l, 26l, 38l, 87l, 81l, 23l, 49l), protein_3 = c(81l, 31l, 5l, 10l, 79l, 40l, 27l, 73l, 64l, 30l, 87l, 64l), protein_4 = c(52l, 15l, 25l, 12l, 63l, 52l, 60l, 33l, 27l, 32l, 53l, 93l), protein_5 = c(19l, 75l, 25l, 14l, 33l, 60l, 73l, 13l, 92l, 92l, 91l, 12l), protein_6 = c(33l, 49l, 29l, 58l, 51l, 12l, 61l, 48l, 71l, 18l, 84l, 31l), protein_7 = c(84l, 57l, 28l, 99l, 47l, 54l, 72l, 97l, 73l, 46l, 68l, 37l), protein_8 = c(15l, 16l, 46l, 95l, 57l, 86l, 30l, 83l, 45l, 12l, 49l, 82l), protein_9 = c(84l, 91l, 33l, 10l, 91l, 91l, 4l, 88l, 42l, 82l, 76l, 95l)), .names = c("individual", "group", "protein_1", "protein_2", "protein_3", "protein_4", "protein_5", "protein_6", "protein_7", "protein_8", "protein_9"), class = "data.frame", row.names = c(na, -12l)) head(df) # individual grouping protein_1 protein_2 protein_3 protein_4 protein_5 protein_6 protein_7 protein_8 protein_9 # 1 1 greenish 82 86 81 52 19 33 84 15 84 # 2 2 bluish 23 50 31 15 75 49 57 16 91 # 3 3 reddish 19 86 5 25 25 29 28 46 33 # 4 4 greenish 100 90 10 12 14 58 99 95 10 # 5 5 bluish 33 37 79 63 33 51 47 57 91 # 6 6 reddish 86 20 40 52 60 12 54 86 91 ?melt df.melted <- melt(df, id.vars = c("individual", "group")) head(df.melted) # individual grouping variable value # 1 1 greenish protein_1 82 # 2 2 bluish protein_1 23 # 3 3 reddish protein_1 19 # 4 4 greenish protein_1 100 # 5 5 bluish protein_1 33 # 6 6 reddish protein_1 86 # first protein # notice using subset() ggplot(data = subset(df.melted, variable == "protein_1"), aes(x = group, y = value)) + geom_boxplot(aes(fill = group))

# sec protein ggplot(data = subset(df.melted, variable == "protein_2"), aes(x = group, y = value)) + geom_boxplot(aes(fill = group))

# , on... # utilize facets ggplot(data = df.melted, aes(x = group, y = value)) + geom_boxplot(aes(fill = group)) + facet_wrap(~ variable)

and yes, realize color groupings not align colors of plot...i leave exercise... have willing tinker, explore, , fail many times.

r ggplot2 boxplot reshape2

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -