[R] metagen - plotStudySizes: order by year and not alphabetical

John Kane jrkrideau at inbox.com
Sat May 30 14:57:09 CEST 2015


Yes you can do it fairly easily in 'basic' ggplot2.  You need to change the references from factors to ordered factors and then plot.

Note your data is now called dat1 as df is an R function. Do ?df to see what it is.

dat1$reference  <- factor(dat1$reference, levels = dat1$reference[order(dat1$year)])
p1  <-  ggplot(dat1, aes( reference, size)) + geom_bar( stat = "identity") + coord_flip()
 p2   <- p1 + ggtitle("Studies with Cross-sectional estimates")
p2


I hope this helps
John Kane
Kingston ON Canada


> -----Original Message-----
> From: antoviral at gmail.com
> Sent: Sat, 30 May 2015 14:01:28 +0200
> To: r-help at r-project.org
> Subject: [R] metagen - plotStudySizes: order by year and not alphabetical
> 
> HI everybody.
> I'm using the package 'metagen' to plot sample size in meta-analysis.
> The plot function of the package reorders the studies by alphabetcial
> order.
> However, I would like to have the studies listed by year.
> How can I force the plotting function to order the study by the variable
> 'year' rather than by the first initial of the variable 'reference'?
> 
> Thank you in advance,
> Antonello
> 
> Here my sample code:
> 
> 
> ### the data
> 
> df <- structure(list(reference = structure(c(3L, 6L, 9L, 2L, 8L, 5L,
> 7L, 10L, 4L, 1L), .Label = c("Bellani et al. 2012             ",
> "Bocco et al. 2004              ", "Costa 1998          ",
> "Dalla Volta et al. 2011           ", "Manzanere et al. 2006
> ",
> "McEnty et al. 2001             ", "Ossian et al. 2006                ",
> "Simone et al. 2004               ", "Tanter et al. 2002         ",
> "Zimmian et al. 2006              "), class = "factor"), size = c(20,
> 288, 70, 138, 475, 191, 918, 80, 508, 205), year = c(1998, 2001,
> 2002, 2004, 2004, 2006, 2006, 2006, 2011, 2012)), .Names = c("reference",
> "size", "year"), class = "data.frame", row.names = c(NA, -10L
> ))
> 
> ### a quick look at the data
> 
> head(df)
> str(df)
> 
> ### the library
> 
> library(metagen); library(ggplot2)
> 
> ### the plot
> 
> p1 <- plotStudySizes(df)
> p1 <- p1 + ggtitle("Studies with Cross-sectional estimates")
> p1
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

____________________________________________________________
FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!



More information about the R-help mailing list