Skip to content
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

Sort ribbon/area in setup_data #3023

Merged
merged 3 commits into from
Dec 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

* ggplot2 now works in Turkish locale (@yutannihilation, #3011).

* `GeomRibbon` and `GeomArea` now sort the data along the x-axis in the
`setup_data()` method rather than as part of `draw_group()` (@thomasp85, #3023)

* `coord_sf()`, `coord_map()`, and `coord_polar()` now squash `-Inf` and `Inf`
into the min and max of the plot (@yutannihilation, #2972).

Expand Down
8 changes: 6 additions & 2 deletions R/geom-ribbon.r
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ GeomRibbon <- ggproto("GeomRibbon", Geom,

required_aes = c("x", "ymin", "ymax"),

setup_data = function(data, params) {
transform(data[order(data$PANEL, data$group, data$x), ], y = ymin)
},

draw_key = draw_key_polygon,

handle_na = function(data, params) {
Expand All @@ -70,7 +74,7 @@ GeomRibbon <- ggproto("GeomRibbon", Geom,

draw_group = function(data, panel_params, coord, na.rm = FALSE) {
if (na.rm) data <- data[stats::complete.cases(data[c("x", "ymin", "ymax")]), ]
data <- data[order(data$group, data$x), ]
data <- data[order(data$group), ]

# Check that aesthetics are constant
aes <- unique(data[c("colour", "fill", "size", "linetype", "alpha")])
Expand Down Expand Up @@ -137,6 +141,6 @@ GeomArea <- ggproto("GeomArea", GeomRibbon,
required_aes = c("x", "y"),

setup_data = function(data, params) {
transform(data, ymin = 0, ymax = y)
transform(data[order(data$PANEL, data$group, data$x), ], ymin = 0, ymax = y)
}
)