-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Need position_stack_line() #2883
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is because (as per the docs) the default position for geom_area is "stack" if you specify "identity" you get the same results. df <- data.frame(x = c(1, 2, 2, 3), y = 1:4)
ggplot(df, aes(x, y)) +
geom_point(color="red")+
geom_area(alpha=0.5,aes(fill="geom_area") ,
position = "identity")+
geom_ribbon(alpha=0.5,aes(ymin = 0, ymax = y,fill="geom_ribbon")) |
That's true, and perhaps points to a potential issue with library(tidyverse)
df <- data.frame(x = c(1, 2, 2, 3), y = 1:4)
df2 <- bind_rows(a = df, b = df, .id = "g")
ggplot(df2, aes(x, y, fill = g)) + geom_area() ggplot(df2, aes(x, y, fill = g)) +
geom_ribbon(aes(ymin = 0, ymax = y), position = "stack") Created on 2018-09-06 by the reprex package (v0.2.0.9000). |
Then again, |
what kind of results you are expecting the above are identical |
Yes, that's why this is probably an issue with I would expect to not have the gaps in between the filled in areas. |
Essentially I would want to get this: library(tidyverse)
df3 <- data.frame(
x = c(1, 2, 2, 3, 1, 2, 2, 3),
y = c(1, 2, 3, 4, 2, 4, 6, 8),
g = rep(c("b", "a"), each = 4)
)
ggplot(df3, aes(x, y, fill = g)) +
geom_area(position = "identity") This matches my intuition of area stacking, but doesn't really fit all that well with how Created on 2018-09-06 by the reprex package (v0.2.0.9000). |
The more I think about this, the more it feels like perhaps this is not an issue with When presenting data like this, only the maximum of the Perhaps some sort of |
I too feel library(tidyverse)
df <- data.frame(x = rep(1:5, each = 2),
y = rep(10 + 1:5, each = 2),
g = rep(c("a", "b"), times = 5))
df$x_jitter <- df$x + 10e-4 * runif(10)
df
#> x y g x_jitter
#> 1 1 11 a 1.000296
#> 2 1 11 b 1.000814
#> 3 2 12 a 2.000061
#> 4 2 12 b 2.000527
#> 5 3 13 a 3.000078
#> 6 3 13 b 3.000748
#> 7 4 14 a 4.000230
#> 8 4 14 b 4.000891
#> 9 5 15 a 5.000595
#> 10 5 15 b 5.000664
library(egg)
#> Loading required package: gridExtra
#>
#> Attaching package: 'gridExtra'
#> The following object is masked from 'package:dplyr':
#>
#> combine
ggarrange(
ggplot(df, aes(x, y, fill = g)) + geom_area(),
ggplot(df, aes(x_jitter, y, fill = g)) + geom_area()
) Created on 2018-09-06 by the reprex package (v0.2.0.9000). |
@yutannihilation yeah I think you're right. Both examples make perfect sense with points, bars, etc. but don't quite "work" with areas (even though when reasoning about it, the behaviour is logical). I read some other issues related to this before posting (#2720, #2802; also just now noticed that this is a duplicate from way back in 2013: #795) and thought this was separate; perhaps not. Maybe it would make sense to have a position adjustment (somewhere) that would handle all of these problems, sort of simulating physical area stacking. That would require automatic interpolation between groups, too, to address the misaligned |
yes stacking time series can be done in several ways for example: |
The Byron & Wattenberg paper is really cool, but I'm not sure it applies to duplicated |
I'm not sure, but I would assume it's been like this for quite a while. The way the stacking algorithm works (replacing |
I've played around this and now feel there's a lot to consider to stack areas properly. I'm afraid this is a bit too complex to implement in ggplot2... https://gist.github.com/yutannihilation/2d3851adc874a02f42914f1655329c71 |
Closed by #4889 library(tidyverse)
df <- data.frame(x = c(1, 2, 2, 3), y = 1:4)
df2 <- bind_rows(a = df, b = df, .id = "g")
ggplot(df2, aes(x, y, fill = g)) + geom_area() Created on 2022-07-07 by the reprex package (v2.0.1) |
geom_area()
doesn't play well with duplicatedx
values. The docs state:But when there are multiple values of
y
for a given value ofx
, the two are not equivalent. Thegeom_ribbon()
result matches the intuition of "geom_line()
but with the area under the curve filled in":However, it seems this scenario results in
geom_area()
having the equivalent ofymin = min(y)
andymax = sum(y)
ingeom_ribbon()
.I'm happy to dig a bit further and see if I can submit a PR for this.
Created on 2018-09-06 by the reprex package (v0.2.0.9000).
The text was updated successfully, but these errors were encountered: