Skip to content

Commit

Permalink
Sort ribbon/area in setup_data (#3023)
Browse files Browse the repository at this point in the history
* Make GeomRibbon/GeomArea sort the data in setup_data in the same manner as GeomLine
  • Loading branch information
thomasp85 committed Dec 4, 2018
1 parent 23a23cd commit a8e9668
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
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)
}
)

0 comments on commit a8e9668

Please sign in to comment.