Question

I am new to ggplot, and using ggplot to show box plots of my data corresponding to different types like this. There are four types. I found that I can use facet_wrap to generate four different graphs.

ggplot(o.xp.sample, aes(power, reduction, fill=interaction(type,power), dodge=type)) +
   stat_boxplot(geom ='errorbar')+
   geom_boxplot() + 
   facet_wrap(~type)

My question is, I want to combine all the four graphs into one graph such that each type has a different color (and slightly transparent to show other plots through). Is this possible?

Here is the data https://gist.github.com/anonymous/9589729

Was it helpful?

Solution

Try this:

library(ggplot2)

o.xp.sample = read.csv("C:\\...\\data.csv",sep=",")

ggplot(o.xp.sample, aes(factor(power), reduction, fill=interaction(type,power), dodge=type)) +
  stat_boxplot(geom ='errorbar') +
  geom_boxplot() +
  theme_bw() + 
  guides(fill = guide_legend(ncol = 3)) #added line as suggested by Paulo Cardoso

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top