R ggplot2 - How to plot 2 boxplots on the same x value -


suppose have 2 boxplots.

trial1 <- ggplot(completiontime, aes(fill=condition, x=scenario, y=trial1)) trial1 + geom_boxplot()+geom_point(position=position_dodge(width=0.75)) + ylim(0, 160)  trial2 <- ggplot(completiontime, aes(fill=condition, x=scenario, y=trial2)) trial2 + geom_boxplot()+geom_point(position=position_dodge(width=0.75)) + ylim(0, 160) 

how can plot trial 1 , trial 2 on same plot , same respective x? have same range of y.

i looked @ geom_boxplot(position="identity"), plots 2 conditions(fill) on same x.

i want plot 2 y column on same x.


edit: dataset

user condition scenario trial1 trial2 1     1        me            67     41 2     1        me        b     70     42 3     1        me        c     40     15 4     1        me        d     65     23 5     1        me        e     45     45 6     1        se           100     34 7     1        se        b     54     23 8     1        se        c     70     23 9     1        se        d     56     15 10    1        se        e     30     20 11    2        me            42     23 12    2        me        b     22     12 13    2        me        c     28      8 14    2        me        d     22      8 15    2        me        e     38     37 16    2        se            59     18 17    2        se        b     65     14 18    2        se        c     75      7 19    2        se        d     37      9 20    2        se        e     31      7 

dput()

structure(list(user = c(1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l,  2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l), condition = structure(c(1l,  1l, 1l, 1l, 1l, 2l, 2l, 2l, 2l, 2l, 1l, 1l, 1l, 1l, 1l, 2l, 2l,  2l, 2l, 2l), .label = c("me", "se"), class = "factor"), scenario =  structure(c(1l,  2l, 3l, 4l, 5l, 1l, 2l, 3l, 4l, 5l, 1l, 2l, 3l, 4l, 5l, 1l, 2l,  3l, 4l, 5l), .label = c("a", "b", "c", "d", "e"), class = "factor"),  trial1 = c(67l, 70l, 40l, 65l, 45l, 100l, 54l, 70l, 56l,  30l, 42l, 22l, 28l, 22l, 38l, 59l, 65l, 75l, 37l, 31l), trial2 = c(41l,  42l, 15l, 23l, 45l, 34l, 23l, 23l, 15l, 20l, 23l, 12l, 8l,  8l, 37l, 18l, 14l, 7l, 9l, 7l)), .names = c("user", "condition",  "scenario", "trial1", "trial2"), class = "data.frame", row.names = c(na,  -20l)) 

you try using interaction combine 2 of factors , plot against third. example, assuming want fill condition in original code:

library(tidyr) completiontime %>%  gather(trial, value, -scenario, -condition, -user) %>% ggplot(aes(interaction(scenario, trial), value)) + geom_boxplot(aes(fill = condition)) 

result: enter image description here


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -