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-tp4391042p4391042.html Sent from the R help mailing list archive at Nabble.com.
It looks like period is a factor, so you can reorder the factor levels however you wish and then plot them the same way. I believe recode() in library(car) is a popular function for doing this, but I haven't used it myself. Michael On Wed, Feb 15, 2012 at 11:34 AM, vd3000 <vd3000 at yahoo.co.uk> 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-tp4391042p4391042.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.
Hi, Micheal, Are you talking about the recode for eliminating "\" problem? I think I am looking for how to eliminate it when I import the data file... THAnks. VD. -- View this message in context: http://r.789695.n4.nabble.com/ggplot-rank-stack-bar-automatically-tp4391042p4393328.html Sent from the R help mailing list archive at Nabble.com.
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.
Hi, Ista, 1. /"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") "/ I have followed your instruction but I found the sequence did not change. 2. I am looking for the stack value, I have read many threads and eventually I think I should make a new frame and reorder it, after order it and put it as a new level for df.m and let it identify the sequence... I am still exploring how to intergrate it to the melt data df.m Thanks... -- View this message in context: http://r.789695.n4.nabble.com/ggplot-rank-stack-bar-automatically-tp4391042p4399172.html Sent from the R help mailing list archive at Nabble.com.
Hi, Here is what I get before reordering: http://izahn.homedns.org/tmp/barplotOriginal.png and after reordering: http://izahn.homedns.org/tmp/barplotReordered.png Are you saying you get something different? Or that this is not what you were trying to do? Best, Ista On Friday, February 17, 2012 08:41:05 PM vd3000 wrote:> Hi, Ista, > > 1. > /"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") "/ > > I have followed your instruction but I found the sequence did not change. > > 2. I am looking for the stack value, I have read many threads and eventually > I think I should make a new frame and reorder it, after order it and put it > as a new level for df.m and let it identify the sequence... > > I am still exploring how to intergrate it to the melt data df.m > > Thanks... > > > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/ggplot-rank-stack-bar-automatically-tp4391042 > p4399172.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.
Hi, Ista, I found the graph were same as "before recording" http://izahn.homedns.org/tmp/barplotOriginal.png Anyway, I will try again, Many thanks. I am now trying to stack it horizontally and found that the axis text overlap each other!! New battle start again. X_X!! VD. -- View this message in context: http://r.789695.n4.nabble.com/ggplot-rank-stack-bar-automatically-tp4391042p4400968.html Sent from the R help mailing list archive at Nabble.com.
Hi VD, The plot should not be the same after reordering. Please show us what you did, and what the result was. Best, Ista On Saturday, February 18, 2012 06:22:00 PM vd3000 wrote:> Hi, Ista, > > > I found the graph were same as "before recording" > http://izahn.homedns.org/tmp/barplotOriginal.png > > Anyway, I will try again, > Many thanks. > > I am now trying to stack it horizontally and found that the axis text > overlap each other!! > New battle start again. X_X!! > > VD. > > -- > View this message in context: > http://r.789695.n4.nabble.com/ggplot-rank-stack-bar-automatically-tp4391042 > p4400968.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.