[R] barchart with bars attached to y=0-line
Felix Andrews
felix at nfrac.org
Thu Jul 17 14:39:06 CEST 2008
## add horizontal grid:
barchart(data=df,Ratio~reorder(Compound, as.numeric(Class))|Class,
origin = 0, scales = list(x = "free"),
panel=function(...) {
panel.grid(h=-1, v=0); panel.barchart(...)})
## make bars all the same width:
library(latticeExtra)
update(trellis.last.object(), layout=c(5,1))
resizePanels()
On Thu, Jul 17, 2008 at 10:03 PM, Henning Wildhagen <HWildhagen at gmx.de> wrote:
> Dear Deepayan and other users,
>
> thanks a lot, that was exactly what i intended to get. However, there are
> some aspects of the plot that can be improved.
> It would be nice to have the same wisth of the bars in all panels. I saw
> the bow.width-argument, but as I understood it is no help to get a fixed
> absolute width of bars in all panels. Is there a solution?
>
> Secondly I would like to get horizontal grid lines at the positions of the
> y-axis tick marks(from -2 to 6, increment |2|). I tried the following:
>
>
> PLOT<-barchart(data=df,Ratio~reorder(Compound,as.numeric(Class))|Class,origin=0,scales=list(x=list(relation="free"),
> y=list(tck=1)))
>
> But this does not work. When using:
>
> P<-barchart(data=df, Ratio~reorder(Compound,as.numeric(Class))|Class,
> origin=0,
> scales=list(x="free",y=list(alternating=3)),ylab="log2 ratio
> (winter/summer)",
> panel=function(...){panel.barchart(...);
>
> grid.grill(v=unit(c(-2,-1,0,1,2,3,4,5,6),"native"),default.units="native")})
>
> i get horizontal lines, but not in correspondence with the y-scaling and
> get some
> vertical lines as well. Where is my mistake? Am i refering to the wrong
> coordinate system (tried with npc, but also did not work)?
>
> Thanks a lot for your help,
>
> Henning
>
>
>
>
>>
>> -------- Original-Nachricht --------
>> Datum: Wed, 16 Jul 2008 09:48:35 -0700
>> Von: "Deepayan Sarkar" <deepayan.sarkar at gmail.com>
>> An: "Henning Wildhagen" <HWildhagen at gmx.de>
>> CC: r-help at r-project.org
>> Betreff: Re: [R] barchart with bars attached to y=0-line
>>
>> On 7/16/08, Henning Wildhagen <HWildhagen at gmx.de> wrote:
>> > Dear R users,
>> >
>> > i am using the following code to produce barcharts with lattice:
>> >
>> > Compound<-c("Glutamine", "Arginine", "Glutamate", "Glycine", "Serine",
>> > "Glucose", "Fructose", "Raffinose",
>> > "Glycerol", "Galacglycerol", "Threitol", "Galactinol", "Galactitol")
>> >
>> >
>> >
>> Class<-c("aminos","aminos","aminos","aminos","aminos","sugars","sugars","sugars","glycerols","glycerols","sugar
>> > alcohols","sugar alcohols","sugar alcohols")
>> >
>> > set.seed(5)
>> > Ratio<-rnorm(13, 0.5, 3)
>> >
>> > df<-data.frame(Compound, Class,Ratio)
>> >
>> > library(lattice)
>> >
>> > P<-barchart(data=df,Ratio~Compound|Class)
>> >
>> > However, I would like to have the bars attached to an imaginary
>> y=0-line so
>> > that they go up if Ratio>0 and down if Ratio<0.
>> > I saw some older entries in the mailing list supposing to use
>> > panel.barchart. However, I did not fully understand the usage of this
>> > function. Also, it was annouced to add an option to "barchart" to make
>> it
>> > easier to get this type of plot.
>> >
>> > Has anyone an idea what the easiest solution might be?
>>
>> barchart(data=df,Ratio~Compound|Class, origin = 0)
>>
>> > A second problem is concerning the display of the "Compound"-objects
>> in
>> > accordance with the conditioning variable "Class". In other words: Is
>> it
>> > possible to use the whole space of each panel for only those
>> > "Compound"-objects which belong to the "Class" displayed in that
>> particular
>> > panel? Of course, for this purpose the panels have to be "detached" to
>> > allow appropiate labling of the x-axis.
>>
>> barchart(data=df,Ratio~Compound|Class, origin = 0,
>> scales = list(x = "free"))
>>
>> But this would work better if the levels of Compound are adjacent
>> within Class; e.g.
>>
>> barchart(data=df,Ratio~reorder(Compound, as.numeric(Class))|Class,
>> origin = 0, scales = list(x = "free"))
>>
>> -Deepayan
>>
>
> --
>
>
>
> [[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 / 安福立
PhD candidate
Integrated Catchment Assessment and Management Centre
The Fenner School of Environment and Society
The Australian National University (Building 48A), ACT 0200
Beijing Bag, Locked Bag 40, Kingston ACT 2604
http://www.neurofractal.org/felix/
3358 543D AAC6 22C2 D336 80D9 360B 72DD 3E4C F5D8
More information about the R-help
mailing list