Dieter Menne
2010-Jan-26 16:05 UTC
[R] Strange tick in ggplot geom_area; and ordering, again
In the area plots below, I see 4 triangle ticks at both sides of the bar; I believe these are non-stacked values for p, but they are definitively confusing. In addition, I would like to get the order of the colors in the plot the same as in the legend, and not arranged alphabetically (the factor is ordered, don't touch my order). Hadley once mentioned an undocumented aestetics "order", but I could not get it to work in the example. Dieter library(ggplot2) cf1 = structure(list(dur = c(10L, 10L, 10L, 10L, 10L, 150L, 150L, 150L, 150L, 150L), score = structure(c(3L, 1L, 4L, 5L, 2L, 3L, 1L, 4L, 5L, 2L), .Label = c("none", "weak", "moderate", "severe", "verysevere"), class = c("ordered", "factor")), p = c(0.04, 0.02, 0.26, 0.6, 0.07, 0.07, 0.05, 0.33, 0.42, 0.14)), .Names = c("dur", "score", "p"), class = c("cast_df", "data.frame")) # columns do not ad to 100% because of rounding; never mind qplot(dur,p,data=cf1, fill=score)+ geom_area() -- View this message in context: http://n4.nabble.com/Strange-tick-in-ggplot-geom-area-and-ordering-again-tp1294692p1294692.html Sent from the R help mailing list archive at Nabble.com.
hadley wickham
2010-Jan-26 16:15 UTC
[R] Strange tick in ggplot geom_area; and ordering, again
Hi Dieter, It looks like a bug: Order works fine with bars: qplot(factor(dur),weight=p,data=cf1, fill=score, geom = "bar", order rev(score)) but not with areas: qplot(dur, p, data=cf1, fill=score, geom = "area", order = rev(score)) I'll add it to my to do list. Hadley On Tue, Jan 26, 2010 at 10:05 AM, Dieter Menne <dieter.menne at menne-biomed.de> wrote:> > In the area plots below, I see 4 triangle ticks at both sides of the bar; I > believe these are non-stacked values for p, but they are definitively > confusing. > > In addition, I would like to get the order of the colors in the plot the > same as in the legend, and not arranged alphabetically (the factor is > ordered, don't touch my order). Hadley once mentioned an undocumented > aestetics "order", but I could not get it to work in the example. > > Dieter > > > library(ggplot2) > cf1 = structure(list(dur = c(10L, 10L, 10L, 10L, 10L, 150L, 150L, > 150L, 150L, 150L), score = structure(c(3L, 1L, 4L, 5L, 2L, 3L, > 1L, 4L, 5L, 2L), .Label = c("none", "weak", "moderate", "severe", > "verysevere"), class = c("ordered", "factor")), p = c(0.04, 0.02, > 0.26, 0.6, 0.07, 0.07, 0.05, 0.33, 0.42, 0.14)), .Names = c("dur", > "score", "p"), class = c("cast_df", "data.frame")) > > # columns do not ad to 100% because of rounding; never mind > > qplot(dur,p,data=cf1, fill=score)+ ?geom_area() > > > -- > View this message in context: http://n4.nabble.com/Strange-tick-in-ggplot-geom-area-and-ordering-again-tp1294692p1294692.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. >-- http://had.co.nz/
Dieter Menne
2010-Jan-26 17:12 UTC
[R] Strange tick in ggplot geom_area; and ordering, again
Hi, Hadley, can you also reproduce the “triangles” problem? Is it just a trivial corollary of the order-bug? Dieter From: hadley wickham [via R] [mailto:ml-node+1294703-876505379@n4.nabble.com] Sent: Tuesday, January 26, 2010 5:18 PM To: Dieter Menne Subject: Re: [R] Strange tick in ggplot geom_area; and ordering, again Hi Dieter, It looks like a bug: Order works fine with bars: qplot(factor(dur),weight=p,data=cf1, fill=score, geom = "bar", order = rev(score)) but not with areas: qplot(dur, p, data=cf1, fill=score, geom = "area", order = rev(score)) I''ll add it to my to do list. -- View this message in context: http://n4.nabble.com/Strange-tick-in-ggplot-geom-area-and-ordering-again-tp1294692p1294763.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]]
Dieter Menne
2010-Jan-26 18:09 UTC
[R] Strange tick in ggplot geom_area; and ordering, again
Hi, Hadley, In case you have a temporary workaround, it would be nice to have it. It’s a show stopper for my report. Bars are not an option, because the curve looks too jaggy. ‘Dieter From: hadley wickham [via R] [mailto:ml-node+1294703-876505379@n4.nabble.com] Sent: Tuesday, January 26, 2010 5:18 PM To: Dieter Menne Subject: Re: [R] Strange tick in ggplot geom_area; and ordering, again Hi Dieter, It looks like a bug: Order works fine with bars: qplot(factor(dur),weight=p,data=cf1, fill=score, geom = "bar", order = rev(score)) but not with areas: -- View this message in context: http://n4.nabble.com/Strange-tick-in-ggplot-geom-area-and-ordering-again-tp1294692p1295444.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]]
hadley wickham
2010-Jan-26 20:47 UTC
[R] Strange tick in ggplot geom_area; and ordering, again
> can you also reproduce the ?triangles? problem? Is it just a trivial corollary of the order-bug?The triangles are there because you have a layer of points (from the qplot default) and layer of areas. Setting geom = "area" in qplot fixes that. Hadley -- http://had.co.nz/
hadley wickham
2010-Jan-26 20:49 UTC
[R] Strange tick in ggplot geom_area; and ordering, again
> > In case you have a temporary workaround, it would be nice to have it. It?s a show stopper for my report. Bars are not an option, because the curve looks too jaggy. >I just remember that to work around the problem, you can just manually order the data frame: cf1 <- cf1[with(cf1, order(dur, score, decreasing = T)), ] qplot(dur,p,data=cf1, fill=score, order = rev(score), geom = "area") Hadley -- http://had.co.nz/