[R] ggplot rank stack bar automatically.

Ista Zahn istazahn at gmail.com
Thu Feb 16 13:47:05 CET 2012


Hi vd,

The answer to the first part of your question is reorder. To continue the 
learnr example:


df.m <- transform(df.m, Period = reorder(Period, -1*value))

ggplot(df.m, aes(x = Period, y = value/1e+06, fill = Region))  +
  geom_bar(stat = "identity", position = "stack")

For the second question: please give a reproducible example.

Best,
Ista

On Wednesday, February 15, 2012 08:34:26 AM vd3000 wrote:
> Hi, all,
> 
> I am currently trying to learn this example.
> http://learnr.wordpress.com/2009/03/17/ggplot2-barplots/
> 
> 
> I created the stack bar easily.
> 
> If I would like to rank the stack bar from the highest on the right,
> shortest on the left and eventually
> I could show the data "1991-00" on the left and  "1823-30" on the right, how
> could I do that?
> 
> Apart from this, I find something quite weird,
> If I import a data frame with column names containing \n, for example,
> pretty\nwoman, lemon\ntree, etc
> for example: f3=as.data.frame(read.table("f3.csv", sep=",", row.names=1,
> header=TRUE, check.names=FALSE))
> even I put check.names=FALSE, the column name will be changed to \\n, ie,
> pretty\\nwoman, lemon\\ntree.
> How could I get rid of extra "\"  sign ???
> 
> 
> 
> Hope some genius could help.
> 
> Thanks in advance.
> 
> vd
> 
> 
> 
> --
> View this message in context:
> http://r.789695.n4.nabble.com/ggplot-rank-stack-bar-automatically-tp4391042
> p4391042.html Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> 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.



More information about the R-help mailing list