Dear R-helpers,

I'm trying to combine two box plots having two dependent variables:

var1- Orange.area and

var2- Iridescent.area;

two independent categorical factors (each has two levels - 'High' & 'Low'):

fact1- Quantity

fact2- Quality


the data frame (df) is:

   Quantity Quality Orange.area Iridescent.area
1      High    High       8.240          12.550
2      High     Low      12.690          10.470
3      High    High      10.340           4.350
4      High     Low      11.430           8.890
5      High    High       6.203           6.809
6       Low     Low       1.750           7.040
7       Low    High       6.060           4.930
8       Low     Low       5.630           5.980
9       Low    High       6.540           5.360
10      Low     Low       8.458           4.710



I tried to plot them with the following codes:

library(ggplot2)
library(gridExtra)
## 1st plot
p1 <- qplot(as.factor(Quantity), Orange.area, data=df, geom = "boxplot",
fill= Quality)
p1 <-p1 + geom_boxplot() +scale_fill_manual(values = c("dark grey",
"white"), legend="FALSE")
p1 <- p1 + labs(x="Quantity", y="Orange area")
p1 <- p1 + stat_summary(fun.y = mean, geom = "point", color = "black",
aes(group=Quality))
p1 <- p1 + stat_summary(fun.y = mean, geom = "line", aes(group = Quality))
p1 <- p1  +theme_bw()+
  theme(axis.line = element_line(colour = "black"),
        strip.text.x = element_blank(),# remove top level title (high and
low)
        strip.background = element_blank(),# remove top level background
        panel.grid.major = element_blank(),# remove grid line within the
plot
        panel.grid.minor = element_blank(),
        panel.border = element_blank())
## 2nd plot
p2 <- qplot(as.factor(Quantity), Iridescent.area, data=df, geom =
"boxplot", fill= Quality)
p2 <-p2 + geom_boxplot() +scale_fill_manual(values = c("dark grey",
"white"))
p2 <- p2 + labs(x="Quantity", y="Iridescent area")
p2 <- p2 + stat_summary(fun.y = mean, geom = "point", color = "black",
aes(group=Quality))
p2 <- p2 + stat_summary(fun.y = mean, geom = "line", aes(group = Quality))
p2 <- p2  +
  theme_bw()+
  theme(axis.line = element_line(colour = "black"),
        strip.text.x = element_blank(),# remove top level title (high and
low)
        strip.background = element_blank(),# remove top level background
        panel.grid.major = element_blank(),# remove grid line within the
plot
        panel.grid.minor = element_blank(),
        panel.border = element_blank())
## combining two plots as one plot
sidebysideplot <- grid.arrange(p1, p2, ncol=2)

and got the plot which sueezed the 2nd plot having legend on its middle of
the right side.

But I want to have the legend on the top right corner with any change of
the 2nd plot (both plots should be the same size).

Is there any help? Any effort will be appreciated...

Cheers,

Moshi
-- 
MD. MOSHIUR RAHMAN
PhD Candidate
School of Animal Biology/Zoology (M092)
University of Western Australia
35 Stirling Hwy, Crawley, WA, 6009
Australia.
Mob.: 061-425205507

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to