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? 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. Many thanks for your help, Henning -- [[alternative HTML version deleted]]
You could do it without a panel function using xyplot and type "h" : df2 <- transform(df, Compound = factor(abbreviate(Compound))) xyplot(Ratio ~ Compound | Class, df2, type = c("h", "g"), lwd = 7, par.settings = list(grid.pars = list(lineend = 1))) On Wed, Jul 16, 2008 at 6:48 AM, 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? > > 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. > > Many thanks for your help, > > Henning > > > -- > > > > [[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. >
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