Dear R users
I would like to group my barplot graph (see example on the R help link). The
proposed R code, adding individual bars to the plot, looks really overwhelming.
My specific dataset just consists of five groups and three different levels
within each groups (the individual bars). The .txt file is read as matrix
(horizontal: group, vertical: levels).
The R trellis barchart (function group="") is an easy function, but
unfortunately the upper plot part look much different from other graphs. I would
therefore prefer barplot to stansdardize my plots within the manuscript.
It would be very helpful for me to know if anyone else has worked on the
barplot group function.
Thanks
Sibylle
http://onertipaday.blogspot.com/2007/05/make-many-barplot-into-one-plot.html
R code from the link
## I have 4 tables like this:satu <- array(c(5,15,20,68,29,54,84,119),
dim=c(2,4), dimnames=list(c("Negative", "Positive"),
c("Black", "Brown", "Red", "Blond")))dua
<- array(c(50,105,30,8,29,25,84,9), dim=c(2,4),
dimnames=list(c("Negative", "Positive"),
c("Black", "Brown", "Red",
"Blond")))tiga <- array(c(9,16,26,68,12,4,84,12), dim=c(2,4),
dimnames=list(c("Negative", "Positive"),
c("Black", "Brown", "Red",
"Blond")))empat <- array(c(25,13,50,78,19,34,84,101), dim=c(2,4),
dimnames=list(c("Negative", "Positive"),
c("Black", "Brown", "Red", "Blond")))#
rbind() the tables togetherTAB <- rbind(satu, dua, tiga, empat)# Do the
barplot and save the bar midpointsmp <- barplot(TAB, beside = TRUE, axisnames
= FALSE)# Add the individual bar labelsmtext(1, at = mp, text = c("N",
"P"),line = 0, cex = 0.5)# Get the midpoints of each sequential pair
of bars# within each of the four groupsat <- t(sapply(seq(1, nrow(TAB), by =
2),function(x) colMeans(mp[c(x, x+1), ])))# Add the group labels for each
pairmtext(1, at = at, text = rep(c("satu", "dua",
"tiga", "empat"), 4),line = 1, cex = 0.75)# Add the color
labels for each groupmtext(1, at = colMeans(mp), text = c("Black",
"Brown", "Red", "Blond"), line = 2)
--
Sicherer, schneller und einfacher. Die aktuellen Internet-Browser -
jetzt kostenlos herunterladen! http://portal.gmx.net/de/go/chbrowser
On 10/29/2010 11:33 PM, "Sibylle St?ckli" wrote:> Dear R users > > > I would like to group my barplot graph (see example on the R help link). The proposed R code, adding individual bars to the plot, looks really overwhelming. My specific dataset just consists of five groups and three different levels within each groups (the individual bars). The .txt file is read as matrix (horizontal: group, vertical: levels). > > The R trellis barchart (function group="") is an easy function, but unfortunately the upper plot part look much different from other graphs. I would therefore prefer barplot to stansdardize my plots within the manuscript. > > It would be very helpful for me to know if anyone else has worked on the barplot group function. >Hi Sibylle, I think you want something like barNest (plotrix). It will plot nested bars to whatever depth of nesting you want (although I don't think anyone would want more than three or four levels), and you can just display the final level if you want. I am competely rewriting this function at the moment to make it more flexible, and there should be a new version of plotrix turning up soon. However, the present function will give you an idea of what it will do. Jim
Dear R users
I would like to group my barplot graph (see example on the R help
link). The proposed R code, adding individual bars to the plot, looks
really overwhelming. My specific dataset just consists of five groups
and three different levels within each groups (the individual bars).
The .txt file is read as matrix (horizontal: group, vertical: levels).
The R trellis barchart (function group="") is an easy function, but
unfortunately the upper plot part look much different from other
graphs. I would therefore prefer barplot to stansdardize my plots
within the manuscript.
It would be very helpful for me to know if anyone else has worked on
the barplot group function.
Thanks
Sibylle
http://onertipaday.blogspot.com/2007/05/make-many-barplot-into-one-plot.html
R code from the link
## I have 4 tables like this:satu <- array(c(5,15,20,68,29,54,84,119),
dim=c(2,4), dimnames=list(c("Negative", "Positive"),
c("Black",
"Brown", "Red", "Blond")))dua <-
array(c(50,105,30,8,29,25,84,9),
dim=c(2,4), dimnames=list(c("Negative", "Positive"),
c("Black",
"Brown", "Red", "Blond")))tiga <-
array(c(9,16,26,68,12,4,84,12),
dim=c(2,4), dimnames=list(c("Negative", "Positive"),
c("Black",
"Brown", "Red", "Blond")))empat <-
array(c(25,13,50,78,19,34,84,101),
dim=c(2,4), dimnames=list(c("Negative", "Positive"),
c("Black",
"Brown", "Red", "Blond")))# rbind() the tables
togetherTAB <-
rbind(satu, dua, tiga, empat)# Do the barplot and save the bar
midpointsmp <- barplot(TAB, beside = TRUE, axisnames = FALSE)# Add the
individual bar labelsmtext(1, at = mp, text = c("N",
"P"),line = 0,
cex = 0.5)# Get the midpoints of each sequential pair of bars# within
each of the four groupsat <- t(sapply(seq(1, nrow(TAB), by =
2),function(x) colMeans(mp[c(x, x+1), ])))# Add the group labels !
for each pairmtext(1, at = at, text = rep(c("satu", "dua",
"tiga",
"empat"), 4),line = 1, cex = 0.75)# Add the color labels for each
groupmtext(1, at = colMeans(mp), text = c("Black", "Brown",
"Red",
"Blond"), line = 2)
[[alternative HTML version deleted]]