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

John Kane jrkrideau at inbox.com
Sat May 30 15:44:03 CEST 2015


Adding a bit of formatting
Where your data is dat1


dat1$reference  <- factor(dat1$reference, levels = dat1$reference[order(dat1$year)])
pp2 <-  ggplot(dat1, aes( reference, size)) + geom_bar( stat = "identity") + coord_flip()
 pp2   <- pp2 + ggtitle("Studies with Cross-sectional estimates") + 
         xlab("") + ylab("Total Number of Subjects")
pp2

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.

____________________________________________________________
Can't remember your password? Do you need a strong and secure password?
Use Password manager! It stores your passwords & protects your account.



More information about the R-help mailing list