[R] ggplot2 / lattice

Felix Andrews felix at nfrac.org
Sat Dec 19 13:03:15 CET 2009


something like

bwplot(val ~ g | G2, dta, pch = "|", box.width = 1,
  par.settings = list(box.rectangle = list(col = "darkred", fill = "grey90"),
                      box.umbrella = list(col = "darkred"),
                      strip.background = list(col = "transparent")))

For more on the Lattice style / theme system, see
show.settings()
str(trellis.par.get())


2009/12/19 Gary Miller <mail2garymiller at gmail.com>:
> Thanks Felix, I got others except:
>
> 1. Is it possible to reduce the gaps between the boxplots, may be say "NO
> GAP".
>
> 2. I tried col="red" option, but its not changing the border color of boxes.
>
> R Code:
>
> g <- rep.int(c("A", "B", "C", "D"), 125)
> t <- rnorm(5000)
> a <- sample(t, 500, replace=TRUE)
> b <- sample(t, 500, replace=TRUE)
> dta <- data.frame(val = sample(t,1000), g = gl(4, 250, labels=c("A", "B",
> "C", "D")) , G2 = gl(2,1, labels=c("XX", "YY")))
> library(lattice)
> bwplot(val ~ g | G2, dta,
>  panel = function(x,y,...)
>  {
>   panel.bwplot(x,y,..., pch="|", col="red", fill="red",
>   box.width=.3)
>       }
> )
>
> Thanks,
> Gary
>
> On Thu, Dec 17, 2009 at 11:01 PM, Felix Andrews <felix at nfrac.org> wrote:
>>
>> Look at ?panel.bwplot specifically 'fill', 'pch', and 'box.width'.
>>
>>
>>
>> 2009/12/18 Gary Miller <mail2garymiller at gmail.com>:
>> > @ Gabor: Thanks, it worked.
>> >
>> > @ All: Which options I should explore to change the appearance of boxes.
>> > Like,
>> >
>> > 1. Color change.
>> > 2. Fill-in boxes with colors.
>> > 3. Change dot to line (used to represent median)
>> > 4. No gaps between boxplots in each category.
>> >
>> > # R Code:
>> > g <- rep.int(c("A", "B", "C", "D"), 125)
>> > t <- rnorm(5000)
>> > a <- sample(t, 500, replace=TRUE)
>> > b <- sample(t, 500, replace=TRUE)
>> > dta <- data.frame(val = sample(t,1000), g = gl(4, 250, labels=c("A",
>> > "B",
>> > "C", "D")) , G2 = gl(2,1, labels=c("XX", "YY")))
>> > library(lattice)
>> > bwplot(val ~ g | G2, dta)
>> >
>> > Thanks,
>> > Gary
>> >
>> > On Thu, Dec 17, 2009 at 10:09 PM, Gabor Grothendieck <
>> > ggrothendieck at gmail.com> wrote:
>> >
>> >> Try this:
>> >>
>> >> bwplot(val ~ g | G2, dta)
>> >>
>> >>
>> >> On Thu, Dec 17, 2009 at 9:34 PM, Gary Miller
>> >> <mail2garymiller at gmail.com>
>> >> wrote:
>> >> > Hi R Users,
>> >> >
>> >> > Is there a equivalent function for the following R code in Lattice
>> >> package.
>> >> > I want to plot a grouped box plots (grouped by two factors).
>> >> >
>> >> > g <- rep.int(c("A", "B", "C", "D"), 125)
>> >> > t <- rnorm(5000)
>> >> > a <- sample(t, 500, replace=TRUE)
>> >> > b <- sample(t, 500, replace=TRUE)
>> >> > dta <- data.frame(val = sample(t,1000), g = gl(4, 250, labels=c("A",
>> >> > "B",
>> >> > "C", "D")) , G2 = gl(2,1, labels=c("XX", "YY")))
>> >> > # ggplot2 package required
>> >> > p <- ggplot(dta, aes(factor(G2), val))
>> >> > p + geom_boxplot(aes(fill = factor(g)))
>> >> >
>> >> > Any suggestion would be highly appreciated!
>> >> > Gary
>> >> >
>> >> >        [[alternative HTML version deleted]]
>> >> >
>> >> > ______________________________________________
>> >> > R-help at 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<http://www.r-project.org/posting-guide.html>
>> >> > and provide commented, minimal, self-contained, reproducible code.
>> >> >
>> >>
>> >
>> >        [[alternative HTML version deleted]]
>> >
>> > ______________________________________________
>> > R-help at 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.
>> >
>>
>>
>>
>> --
>> Felix Andrews / 安福立
>> Postdoctoral Fellow
>> Integrated Catchment Assessment and Management (iCAM) Centre
>> Fenner School of Environment and Society [Bldg 48a]
>> The Australian National University
>> Canberra ACT 0200 Australia
>> M: +61 410 400 963
>> T: + 61 2 6125 4670
>> E: felix.andrews at anu.edu.au
>> CRICOS Provider No. 00120C
>> --
>> http://www.neurofractal.org/felix/
>
>



-- 
Felix Andrews / 安福立
Postdoctoral Fellow
Integrated Catchment Assessment and Management (iCAM) Centre
Fenner School of Environment and Society [Bldg 48a]
The Australian National University
Canberra ACT 0200 Australia
M: +61 410 400 963
T: + 61 2 6125 4670
E: felix.andrews at anu.edu.au
CRICOS Provider No. 00120C
-- 
http://www.neurofractal.org/felix/




More information about the R-help mailing list