unknown
unknown

Reputation: 883

how to present data with multiple conditions

I have some data from an experiment that has 7 variables that have two levels to generate the conditions for the experiment. Consequently there are 128 (2^7) different combinations of variables. I've seen some data presented in lattice style panel plots that look good, but I've only come across ones that do this for 2 different variables. However, I was wondering if anyone had any ideas for presenting data where there are more than 2 variables (i.e. a contingency table doesn't work!)

I've provided some example data to explain what my data looks like if it wasn't clear:

cond1 <- c(1,2)
cond2 <- c(1,2)
cond3 <- c(1,2)
cond4 <- c(1,2)
cond5 <- c(1,2)
cond6 <- c(1,2)
cond7 <- c(1,2)
conditions <- expand.grid(cond1,cond2,cond3,cond4,cond5,cond6,cond7)
conditions <- sapply(conditions, rep.int, times=10)
data <- runif (nrow(conditions))
df1 <- cbind(conditions, data)

Upvotes: 2

Views: 587

Answers (2)

drf
drf

Reputation: 8699

One presentation option would be to split the 7 variables into two groups, and present the result as a facet grid:

df<-mutate(data.frame(df1), 
    V14=factor(paste0(Var1, Var2, Var3, Var4, "___")),
    V57=factor(paste0("___", Var5, Var6, Var7)))

ggplot(df) +
    geom_density(aes(x=data)) +
    facet_grid(V14~V57, switch="y") +
    scale_x_continuous(breaks=c(0,1)) +
    theme(
        axis.text.y=element_blank(),
        axis.ticks.y=element_blank()
    ) +
    xlab("data") + ylab("")

facet grid

Upvotes: 1

Roman Luštrik
Roman Luštrik

Reputation: 70653

I can do 6 right out of the box and if you plot the same plot for each level in Var7, you've got 7 dimensions. They could probably use some tweaking.

df1 <- data.frame(df1)

library(ggplot2)
xy1 <- ggplot(droplevels(df1[df1$Var7 == 1,]), aes(x = as.factor(Var1),
                y = as.factor(Var2),
                color = as.factor(Var3), 
                shape = as.factor(Var4), 
                alpha = Var5,
                size = data)) +
  geom_jitter() +
  facet_wrap(~ as.factor(Var6))

xy2 <- ggplot(droplevels(df1[df1$Var7 == 2,]), aes(x = as.factor(Var1),
                                            y = as.factor(Var2),
                                            color = as.factor(Var3), 
                                            shape = as.factor(Var4), 
                                            alpha = Var5,
                                            size = data)) +
  geom_jitter() +
  facet_wrap(~ as.factor(Var6))

library(gridExtra)

grid.arrange(xy1, xy2, ncol = 1)

enter image description here

Upvotes: 1

Related Questions