From 3d26626818fe0acd212359ab231ee518b2209782 Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Thu, 27 Dec 2018 13:40:47 +0900 Subject: [PATCH 01/15] Add lineend and linejoin params to geom_rect() and geom_tile() --- R/geom-rect.r | 10 ++++++++-- R/geom-tile.r | 5 +++++ man/geom_tile.Rd | 12 ++++++++---- tests/testthat/test-geom-tile.R | 12 ++++++++++++ 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/R/geom-rect.r b/R/geom-rect.r index c8d03e5121..f55bf03c41 100644 --- a/R/geom-rect.r +++ b/R/geom-rect.r @@ -3,6 +3,8 @@ geom_rect <- function(mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., + lineend = "square", + linejoin = "mitre", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) { @@ -15,6 +17,8 @@ geom_rect <- function(mapping = NULL, data = NULL, show.legend = show.legend, inherit.aes = inherit.aes, params = list( + lineend = lineend, + linejoin = linejoin, na.rm = na.rm, ... ) @@ -31,7 +35,8 @@ GeomRect <- ggproto("GeomRect", Geom, required_aes = c("xmin", "xmax", "ymin", "ymax"), - draw_panel = function(self, data, panel_params, coord) { + draw_panel = function(self, data, panel_params, coord, + lineend = "square", linejoin = "mitre") { if (!coord$is_linear()) { aesthetics <- setdiff( names(data), c("x", "y", "xmin", "xmax", "ymin", "ymax") @@ -58,7 +63,8 @@ GeomRect <- ggproto("GeomRect", Geom, fill = alpha(coords$fill, coords$alpha), lwd = coords$size * .pt, lty = coords$linetype, - lineend = "butt" + lineend = lineend, + linejoin = linejoin ) )) } diff --git a/R/geom-tile.r b/R/geom-tile.r index 3ffb97ae03..1b3932764e 100644 --- a/R/geom-tile.r +++ b/R/geom-tile.r @@ -10,6 +10,7 @@ #' @eval rd_aesthetics("geom", "tile") #' @inheritParams layer #' @inheritParams geom_point +#' @inheritParams geom_segment #' @export #' @examples #' # The most common use for rectangles is to draw a surface. You always want @@ -57,6 +58,8 @@ geom_tile <- function(mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., + lineend = "square", + linejoin = "mitre", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) { @@ -69,6 +72,8 @@ geom_tile <- function(mapping = NULL, data = NULL, show.legend = show.legend, inherit.aes = inherit.aes, params = list( + lineend = lineend, + linejoin = linejoin, na.rm = na.rm, ... ) diff --git a/man/geom_tile.Rd b/man/geom_tile.Rd index e350939914..5d6c020a71 100644 --- a/man/geom_tile.Rd +++ b/man/geom_tile.Rd @@ -12,12 +12,12 @@ geom_raster(mapping = NULL, data = NULL, stat = "identity", inherit.aes = TRUE) geom_rect(mapping = NULL, data = NULL, stat = "identity", - position = "identity", ..., na.rm = FALSE, show.legend = NA, - inherit.aes = TRUE) + position = "identity", ..., lineend = "square", linejoin = "mitre", + na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) geom_tile(mapping = NULL, data = NULL, stat = "identity", - position = "identity", ..., na.rm = FALSE, show.legend = NA, - inherit.aes = TRUE) + position = "identity", ..., lineend = "square", linejoin = "mitre", + na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) } \arguments{ \item{mapping}{Set of aesthetic mappings created by \code{\link[=aes]{aes()}} or @@ -70,6 +70,10 @@ display.} rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification, e.g. \code{\link[=borders]{borders()}}.} + +\item{lineend}{Line end style (round, butt, square).} + +\item{linejoin}{Line join style (round, mitre, bevel).} } \description{ \code{geom_rect} and \code{geom_tile} do the same thing, but are diff --git a/tests/testthat/test-geom-tile.R b/tests/testthat/test-geom-tile.R index 46ee3094e9..07bab98bb1 100644 --- a/tests/testthat/test-geom-tile.R +++ b/tests/testthat/test-geom-tile.R @@ -26,3 +26,15 @@ test_that("accepts width and height aesthetics", { )) expect_equal(out[c("xmin", "xmax", "ymin", "ymax")], boundary) }) + +test_that("accepts lineend and linejoin parameters", { + df <- data_frame(x = c("a", "b"), y = c("a", "b")) + + gp1 <- layer_grob(ggplot(df, aes(x, y)) + geom_tile())[[1]]$gp + expect_equal(gp1$lineend, "square") + expect_equal(gp1$linejoin, "mitre") + + gp2 <- layer_grob(ggplot(df, aes(x, y)) + geom_tile(lineend = "butt", linejoin = "round"))[[1]]$gp + expect_equal(gp2$lineend, "butt") + expect_equal(gp2$linejoin, "round") +}) From 24cb3808a50f1a2f089a6bad977f84cc3ba74b13 Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Thu, 27 Dec 2018 14:01:38 +0900 Subject: [PATCH 02/15] Add a NEWS bullet --- NEWS.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS.md b/NEWS.md index 313dc17df7..266090ba95 100644 --- a/NEWS.md +++ b/NEWS.md @@ -27,6 +27,10 @@ * `coord_sf()`, `coord_map()`, and `coord_polar()` now squash `-Inf` and `Inf` into the min and max of the plot (@yutannihilation, #2972). +* `geom_tile()` and `geom_rect()` now draw rectangles without notches at the + corners. The style of the corner can be controlled by `lineend` and `linejoin` + parameters (@yutannihilation, #3050). + # ggplot2 3.1.0 ## Breaking changes From fbc0500030ad8a82127af8757e798db76f0ac982 Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Thu, 27 Dec 2018 14:39:15 +0900 Subject: [PATCH 03/15] Update vdiffr cases --- .../stat-count-width-0-5.svg | 6 +++--- tests/figs/creating-aesthetic-mappings/stat-count.svg | 6 +++--- .../stat-identity-width-0-5.svg | 6 +++--- .../figs/creating-aesthetic-mappings/stat-identity.svg | 6 +++--- .../cartesian-lines-intersect-mid-bars.svg | 10 +++++----- .../flipped-lines-intersect-mid-bars.svg | 10 +++++----- ...end-inside-plot-bottom-left-of-legend-at-center.svg | 6 +++--- tests/figs/guides/legend-inside-plot-bottom-left.svg | 6 +++--- tests/figs/guides/legend-inside-plot-centered.svg | 6 +++--- tests/figs/guides/legend-inside-plot-top-right.svg | 6 +++--- tests/figs/guides/padding-in-legend-box.svg | 6 +++--- 11 files changed, 37 insertions(+), 37 deletions(-) diff --git a/tests/figs/creating-aesthetic-mappings/stat-count-width-0-5.svg b/tests/figs/creating-aesthetic-mappings/stat-count-width-0-5.svg index 361a604464..03be4ea394 100644 --- a/tests/figs/creating-aesthetic-mappings/stat-count-width-0-5.svg +++ b/tests/figs/creating-aesthetic-mappings/stat-count-width-0-5.svg @@ -19,9 +19,9 @@ - - - + + + diff --git a/tests/figs/creating-aesthetic-mappings/stat-count.svg b/tests/figs/creating-aesthetic-mappings/stat-count.svg index 9d7a1ecd7d..f6dc541233 100644 --- a/tests/figs/creating-aesthetic-mappings/stat-count.svg +++ b/tests/figs/creating-aesthetic-mappings/stat-count.svg @@ -19,9 +19,9 @@ - - - + + + diff --git a/tests/figs/creating-aesthetic-mappings/stat-identity-width-0-5.svg b/tests/figs/creating-aesthetic-mappings/stat-identity-width-0-5.svg index c210c3e35a..255ecba122 100644 --- a/tests/figs/creating-aesthetic-mappings/stat-identity-width-0-5.svg +++ b/tests/figs/creating-aesthetic-mappings/stat-identity-width-0-5.svg @@ -19,9 +19,9 @@ - - - + + + diff --git a/tests/figs/creating-aesthetic-mappings/stat-identity.svg b/tests/figs/creating-aesthetic-mappings/stat-identity.svg index 74ae75acc8..c767412876 100644 --- a/tests/figs/creating-aesthetic-mappings/stat-identity.svg +++ b/tests/figs/creating-aesthetic-mappings/stat-identity.svg @@ -19,9 +19,9 @@ - - - + + + diff --git a/tests/figs/geom-hline-vline-abline/cartesian-lines-intersect-mid-bars.svg b/tests/figs/geom-hline-vline-abline/cartesian-lines-intersect-mid-bars.svg index 033d756bac..36e6c691c0 100644 --- a/tests/figs/geom-hline-vline-abline/cartesian-lines-intersect-mid-bars.svg +++ b/tests/figs/geom-hline-vline-abline/cartesian-lines-intersect-mid-bars.svg @@ -19,11 +19,11 @@ - - - - - + + + + + diff --git a/tests/figs/geom-hline-vline-abline/flipped-lines-intersect-mid-bars.svg b/tests/figs/geom-hline-vline-abline/flipped-lines-intersect-mid-bars.svg index 1cf2e02a61..c542172c56 100644 --- a/tests/figs/geom-hline-vline-abline/flipped-lines-intersect-mid-bars.svg +++ b/tests/figs/geom-hline-vline-abline/flipped-lines-intersect-mid-bars.svg @@ -19,11 +19,11 @@ - - - - - + + + + + diff --git a/tests/figs/guides/legend-inside-plot-bottom-left-of-legend-at-center.svg b/tests/figs/guides/legend-inside-plot-bottom-left-of-legend-at-center.svg index a35ee3aedb..5b110afb25 100644 --- a/tests/figs/guides/legend-inside-plot-bottom-left-of-legend-at-center.svg +++ b/tests/figs/guides/legend-inside-plot-bottom-left-of-legend-at-center.svg @@ -19,9 +19,9 @@ - - - + + + diff --git a/tests/figs/guides/legend-inside-plot-bottom-left.svg b/tests/figs/guides/legend-inside-plot-bottom-left.svg index 1a08268309..05fc30a539 100644 --- a/tests/figs/guides/legend-inside-plot-bottom-left.svg +++ b/tests/figs/guides/legend-inside-plot-bottom-left.svg @@ -19,9 +19,9 @@ - - - + + + diff --git a/tests/figs/guides/legend-inside-plot-centered.svg b/tests/figs/guides/legend-inside-plot-centered.svg index 6274018d88..21509081da 100644 --- a/tests/figs/guides/legend-inside-plot-centered.svg +++ b/tests/figs/guides/legend-inside-plot-centered.svg @@ -19,9 +19,9 @@ - - - + + + diff --git a/tests/figs/guides/legend-inside-plot-top-right.svg b/tests/figs/guides/legend-inside-plot-top-right.svg index 1f74bf01be..e5d767f21b 100644 --- a/tests/figs/guides/legend-inside-plot-top-right.svg +++ b/tests/figs/guides/legend-inside-plot-top-right.svg @@ -19,9 +19,9 @@ - - - + + + diff --git a/tests/figs/guides/padding-in-legend-box.svg b/tests/figs/guides/padding-in-legend-box.svg index f018da9241..105c8417f8 100644 --- a/tests/figs/guides/padding-in-legend-box.svg +++ b/tests/figs/guides/padding-in-legend-box.svg @@ -19,9 +19,9 @@ - - - + + + From 43eafa85634156fe35901e5c732ee3900c5c0449 Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Fri, 25 Jan 2019 17:56:18 +0900 Subject: [PATCH 04/15] Remove lineend and fix rect_to_poly() --- R/geom-rect.r | 10 +++------- R/geom-tile.r | 2 -- man/geom_tile.Rd | 10 ++++------ 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/R/geom-rect.r b/R/geom-rect.r index f55bf03c41..e2ec11030a 100644 --- a/R/geom-rect.r +++ b/R/geom-rect.r @@ -3,7 +3,6 @@ geom_rect <- function(mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., - lineend = "square", linejoin = "mitre", na.rm = FALSE, show.legend = NA, @@ -17,7 +16,6 @@ geom_rect <- function(mapping = NULL, data = NULL, show.legend = show.legend, inherit.aes = inherit.aes, params = list( - lineend = lineend, linejoin = linejoin, na.rm = na.rm, ... @@ -35,8 +33,7 @@ GeomRect <- ggproto("GeomRect", Geom, required_aes = c("xmin", "xmax", "ymin", "ymax"), - draw_panel = function(self, data, panel_params, coord, - lineend = "square", linejoin = "mitre") { + draw_panel = function(self, data, panel_params, coord, linejoin = "mitre") { if (!coord$is_linear()) { aesthetics <- setdiff( names(data), c("x", "y", "xmin", "xmax", "ymin", "ymax") @@ -63,7 +60,6 @@ GeomRect <- ggproto("GeomRect", Geom, fill = alpha(coords$fill, coords$alpha), lwd = coords$size * .pt, lty = coords$linetype, - lineend = lineend, linejoin = linejoin ) )) @@ -80,7 +76,7 @@ GeomRect <- ggproto("GeomRect", Geom, # @keyword internal rect_to_poly <- function(xmin, xmax, ymin, ymax) { new_data_frame(list( - y = c(ymax, ymax, ymin, ymin, ymax), - x = c(xmin, xmax, xmax, xmin, xmin) + y = c(ymax, ymax, ymin, ymin), + x = c(xmin, xmax, xmax, xmin) )) } diff --git a/R/geom-tile.r b/R/geom-tile.r index 1b3932764e..8c31e32148 100644 --- a/R/geom-tile.r +++ b/R/geom-tile.r @@ -58,7 +58,6 @@ geom_tile <- function(mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., - lineend = "square", linejoin = "mitre", na.rm = FALSE, show.legend = NA, @@ -72,7 +71,6 @@ geom_tile <- function(mapping = NULL, data = NULL, show.legend = show.legend, inherit.aes = inherit.aes, params = list( - lineend = lineend, linejoin = linejoin, na.rm = na.rm, ... diff --git a/man/geom_tile.Rd b/man/geom_tile.Rd index 5d6c020a71..65c18f91e5 100644 --- a/man/geom_tile.Rd +++ b/man/geom_tile.Rd @@ -12,12 +12,12 @@ geom_raster(mapping = NULL, data = NULL, stat = "identity", inherit.aes = TRUE) geom_rect(mapping = NULL, data = NULL, stat = "identity", - position = "identity", ..., lineend = "square", linejoin = "mitre", - na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) + position = "identity", ..., linejoin = "mitre", na.rm = FALSE, + show.legend = NA, inherit.aes = TRUE) geom_tile(mapping = NULL, data = NULL, stat = "identity", - position = "identity", ..., lineend = "square", linejoin = "mitre", - na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) + position = "identity", ..., linejoin = "mitre", na.rm = FALSE, + show.legend = NA, inherit.aes = TRUE) } \arguments{ \item{mapping}{Set of aesthetic mappings created by \code{\link[=aes]{aes()}} or @@ -71,8 +71,6 @@ rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification, e.g. \code{\link[=borders]{borders()}}.} -\item{lineend}{Line end style (round, butt, square).} - \item{linejoin}{Line join style (round, mitre, bevel).} } \description{ From 068da3e615a4975e5ded41957d674b01b5b16dd8 Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Tue, 29 Jan 2019 13:01:06 +0900 Subject: [PATCH 05/15] Specify lineend = "square" as a workaround for Windows --- R/geom-rect.r | 1 + R/legend-draw.r | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/R/geom-rect.r b/R/geom-rect.r index e2ec11030a..981f1939e4 100644 --- a/R/geom-rect.r +++ b/R/geom-rect.r @@ -60,6 +60,7 @@ GeomRect <- ggproto("GeomRect", Geom, fill = alpha(coords$fill, coords$alpha), lwd = coords$size * .pt, lty = coords$linetype, + lineend = "square", # workaround for Windows linejoin = linejoin ) )) diff --git a/R/legend-draw.r b/R/legend-draw.r index c3efc22b3b..195d0615ce 100644 --- a/R/legend-draw.r +++ b/R/legend-draw.r @@ -49,7 +49,8 @@ draw_key_rect <- function(data, params, size) { rectGrob(gp = gpar( col = NA, fill = alpha(data$fill, data$alpha), - lty = data$linetype + lty = data$linetype, + lineend = "square" # workaround for Windows )) } #' @export From 216b0a544ad0aa81c7dafe937efbcc31f99a160c Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Tue, 29 Jan 2019 13:08:48 +0900 Subject: [PATCH 06/15] Match the repetition to the length of poly --- R/geom-rect.r | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/geom-rect.r b/R/geom-rect.r index 981f1939e4..544b8fd156 100644 --- a/R/geom-rect.r +++ b/R/geom-rect.r @@ -41,7 +41,7 @@ GeomRect <- ggproto("GeomRect", Geom, polys <- lapply(split(data, seq_len(nrow(data))), function(row) { poly <- rect_to_poly(row$xmin, row$xmax, row$ymin, row$ymax) - aes <- new_data_frame(row[aesthetics])[rep(1,5), ] + aes <- new_data_frame(row[aesthetics])[rep(1,4), ] GeomPolygon$draw_panel(cbind(poly, aes), panel_params, coord) }) From 2bb30e7a4313fdaf39579dc9233b160129652997 Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Tue, 29 Jan 2019 13:09:46 +0900 Subject: [PATCH 07/15] Fix tests --- tests/testthat/test-geom-tile.R | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-geom-tile.R b/tests/testthat/test-geom-tile.R index 07bab98bb1..f3ac11d189 100644 --- a/tests/testthat/test-geom-tile.R +++ b/tests/testthat/test-geom-tile.R @@ -27,14 +27,12 @@ test_that("accepts width and height aesthetics", { expect_equal(out[c("xmin", "xmax", "ymin", "ymax")], boundary) }) -test_that("accepts lineend and linejoin parameters", { +test_that("accepts linejoin parameter", { df <- data_frame(x = c("a", "b"), y = c("a", "b")) gp1 <- layer_grob(ggplot(df, aes(x, y)) + geom_tile())[[1]]$gp - expect_equal(gp1$lineend, "square") expect_equal(gp1$linejoin, "mitre") - gp2 <- layer_grob(ggplot(df, aes(x, y)) + geom_tile(lineend = "butt", linejoin = "round"))[[1]]$gp - expect_equal(gp2$lineend, "butt") + gp2 <- layer_grob(ggplot(df, aes(x, y)) + geom_tile(linejoin = "round"))[[1]]$gp expect_equal(gp2$linejoin, "round") }) From d63667361f0b7d3cabf6d4b523a8666775ee6975 Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Tue, 29 Jan 2019 13:26:39 +0900 Subject: [PATCH 08/15] Update NEWS --- NEWS.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index c202273e6f..c1edcaf561 100644 --- a/NEWS.md +++ b/NEWS.md @@ -50,8 +50,8 @@ * `stat_bin()` now handles data with only one unique value (@yutannihilation #3047). * `geom_tile()` and `geom_rect()` now draw rectangles without notches at the - corners. The style of the corner can be controlled by `lineend` and `linejoin` - parameters (@yutannihilation, #3050). + corners. The style of the corner can be controlled by `linejoin` parameters + (@yutannihilation, #3050). # ggplot2 3.1.0 From 4884b1848fd8c80d9a11ab8f704ccf4739afaeff Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Wed, 24 Apr 2019 08:48:00 +0900 Subject: [PATCH 09/15] Revert rect_to_poly() and add some notes --- R/geom-rect.r | 11 +++++++---- man/theme.Rd | 13 +++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/R/geom-rect.r b/R/geom-rect.r index 544b8fd156..60fb1ea94e 100644 --- a/R/geom-rect.r +++ b/R/geom-rect.r @@ -41,7 +41,7 @@ GeomRect <- ggproto("GeomRect", Geom, polys <- lapply(split(data, seq_len(nrow(data))), function(row) { poly <- rect_to_poly(row$xmin, row$xmax, row$ymin, row$ymax) - aes <- new_data_frame(row[aesthetics])[rep(1,4), ] + aes <- new_data_frame(row[aesthetics])[rep(1,5), ] GeomPolygon$draw_panel(cbind(poly, aes), panel_params, coord) }) @@ -72,12 +72,15 @@ GeomRect <- ggproto("GeomRect", Geom, # Convert rectangle to polygon -# Useful for non-Cartesian coordinate systems where it's easy to work purely in terms of locations, rather than locations and dimensions. +# Useful for non-Cartesian coordinate systems where it's easy to work purely in +# terms of locations, rather than locations and dimensions. Note that, though +# `polygonGrob()` expects an open form, closed form is needed for correct +# munching (c.f. https://github.com/tidyverse/ggplot2/issues/3037#issuecomment-458406857). # # @keyword internal rect_to_poly <- function(xmin, xmax, ymin, ymax) { new_data_frame(list( - y = c(ymax, ymax, ymin, ymin), - x = c(xmin, xmax, xmax, xmin) + y = c(ymax, ymax, ymin, ymin, ymax), + x = c(xmin, xmax, xmax, xmin, xmax) )) } diff --git a/man/theme.Rd b/man/theme.Rd index 2591925f4a..3d5af33dbf 100644 --- a/man/theme.Rd +++ b/man/theme.Rd @@ -251,15 +251,20 @@ p1 + theme( ) # Axes ---------------------------------------------------------------------- +# Change styles of axes texts and lines p1 + theme(axis.line = element_line(size = 3, colour = "grey80")) p1 + theme(axis.text = element_text(colour = "blue")) p1 + theme(axis.ticks = element_line(size = 2)) + +# Change the appearance of the y-axis title +p1 + theme(axis.title.y = element_text(size = rel(1.5), angle = 90)) + +# Make ticks point outwards on y-axis and inwards on x-axis p1 + theme( - axis.ticks.length.y = unit(.25, "cm"), - axis.ticks.length.x = unit(-.25, "cm"), - axis.text.x=element_text(margin=margin(t=.3, unit="cm")) + axis.ticks.length.y = unit(.25, "cm"), + axis.ticks.length.x = unit(-.25, "cm"), + axis.text.x = element_text(margin = margin(t = .3, unit = "cm")) ) -p1 + theme(axis.title.y = element_text(size = rel(1.5), angle = 90)) \donttest{ # Legend -------------------------------------------------------------------- From 2fb6c3f10684ba5c2063735e7c27f5e76ff40417 Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Thu, 25 Apr 2019 09:07:27 +0900 Subject: [PATCH 10/15] Fix incomplete revert of rect_to_poly() --- R/geom-rect.r | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/geom-rect.r b/R/geom-rect.r index 60fb1ea94e..123d1a1ab1 100644 --- a/R/geom-rect.r +++ b/R/geom-rect.r @@ -81,6 +81,6 @@ GeomRect <- ggproto("GeomRect", Geom, rect_to_poly <- function(xmin, xmax, ymin, ymax) { new_data_frame(list( y = c(ymax, ymax, ymin, ymin, ymax), - x = c(xmin, xmax, xmax, xmin, xmax) + x = c(xmin, xmax, xmax, xmin, xmin) )) } From 91aeb988b2cdfd826865c0efa25cb151122e5945 Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Thu, 25 Apr 2019 09:14:40 +0900 Subject: [PATCH 11/15] Fix lineend --- R/geom-rect.r | 6 ++++-- tests/figs/geom-raster/irregular-categorical.svg | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/R/geom-rect.r b/R/geom-rect.r index 123d1a1ab1..95cf0383e6 100644 --- a/R/geom-rect.r +++ b/R/geom-rect.r @@ -60,8 +60,10 @@ GeomRect <- ggproto("GeomRect", Geom, fill = alpha(coords$fill, coords$alpha), lwd = coords$size * .pt, lty = coords$linetype, - lineend = "square", # workaround for Windows - linejoin = linejoin + linejoin = linejoin, + # `lineend` is a workaround for Windows and intentionally kept unexposed + # as an argument. (c.f. https://github.com/tidyverse/ggplot2/issues/3037#issuecomment-457504667) + lineend = if (identical(linejoin, "round")) "round" else "square" ) )) } diff --git a/tests/figs/geom-raster/irregular-categorical.svg b/tests/figs/geom-raster/irregular-categorical.svg index c856b08472..6e102aa260 100644 --- a/tests/figs/geom-raster/irregular-categorical.svg +++ b/tests/figs/geom-raster/irregular-categorical.svg @@ -51,11 +51,11 @@ factor(col) - + - + - + 0 1 NA From 1435bbaf4e3538a16b7efa35d342675b665980ad Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Thu, 25 Apr 2019 09:35:27 +0900 Subject: [PATCH 12/15] Fix legend --- R/legend-draw.r | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/R/legend-draw.r b/R/legend-draw.r index 195d0615ce..5a82d05361 100644 --- a/R/legend-draw.r +++ b/R/legend-draw.r @@ -50,7 +50,10 @@ draw_key_rect <- function(data, params, size) { col = NA, fill = alpha(data$fill, data$alpha), lty = data$linetype, - lineend = "square" # workaround for Windows + linejoin = data$linejoin, + # `lineend` is a workaround for Windows and intentionally kept unexposed + # as an argument. (c.f. https://github.com/tidyverse/ggplot2/issues/3037#issuecomment-457504667) + lineend = if (identical(data$linejoin, "round")) "round" else "square" )) } #' @export From 2d1ea20e8258257f8f5144f0c1af4241db25067b Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Wed, 1 May 2019 11:41:39 +0900 Subject: [PATCH 13/15] Update visual cases --- .../geom-raster/irregular-categorical.svg | 6 ++--- .../functional-limits.svg | 24 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/figs/geom-raster/irregular-categorical.svg b/tests/figs/geom-raster/irregular-categorical.svg index 6e102aa260..c856b08472 100644 --- a/tests/figs/geom-raster/irregular-categorical.svg +++ b/tests/figs/geom-raster/irregular-categorical.svg @@ -51,11 +51,11 @@ factor(col) - + - + - + 0 1 NA diff --git a/tests/figs/scales-breaks-and-labels/functional-limits.svg b/tests/figs/scales-breaks-and-labels/functional-limits.svg index 961969a880..5abb86fc4a 100644 --- a/tests/figs/scales-breaks-and-labels/functional-limits.svg +++ b/tests/figs/scales-breaks-and-labels/functional-limits.svg @@ -19,18 +19,18 @@ - - - - - - - - - - - - + + + + + + + + + + + + From 99cdc915cb0421c48434f948fc23056dcd5d5ec2 Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Wed, 1 May 2019 13:12:47 +0900 Subject: [PATCH 14/15] Revert draw_key_rect() and modify draw_key_polygon() --- R/legend-draw.r | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/R/legend-draw.r b/R/legend-draw.r index f467c4f818..6e51a63488 100644 --- a/R/legend-draw.r +++ b/R/legend-draw.r @@ -60,11 +60,7 @@ draw_key_rect <- function(data, params, size) { rectGrob(gp = gpar( col = NA, fill = alpha(data$fill %||% data$colour %||% "grey20", data$alpha), - lty = data$linetype %||% 1, - linejoin = data$linejoin, - # `lineend` is a workaround for Windows and intentionally kept unexposed - # as an argument. (c.f. https://github.com/tidyverse/ggplot2/issues/3037#issuecomment-457504667) - lineend = if (identical(data$linejoin, "round")) "round" else "square" + lty = data$linetype %||% 1 )) } #' @export @@ -84,7 +80,10 @@ draw_key_polygon <- function(data, params, size) { fill = alpha(data$fill %||% "grey20", data$alpha), lty = data$linetype %||% 1, lwd = lwd * .pt, - linejoin = "mitre" + linejoin = params$linejoin %||% "mitre", + # `lineend` is a workaround for Windows and intentionally kept unexposed + # as an argument. (c.f. https://github.com/tidyverse/ggplot2/issues/3037#issuecomment-457504667) + lineend = if (identical(params$linejoin, "round")) "round" else "square" )) } From f97b96148fbf7812091ef127a3108f5452ceee43 Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Wed, 1 May 2019 13:13:19 +0900 Subject: [PATCH 15/15] Update visual cases --- tests/figs/geom-violin/dodging-and-coord-flip.svg | 6 +++--- tests/figs/geom-violin/dodging.svg | 6 +++--- .../geom-violin/grouping-on-x-and-fill-dodge-width-0-5.svg | 4 ++-- tests/figs/geom-violin/grouping-on-x-and-fill.svg | 4 ++-- .../legend-inside-plot-bottom-left-of-legend-at-center.svg | 6 +++--- tests/figs/guides/legend-inside-plot-bottom-left.svg | 6 +++--- tests/figs/guides/legend-inside-plot-centered.svg | 6 +++--- tests/figs/guides/legend-inside-plot-top-right.svg | 6 +++--- tests/figs/guides/padding-in-legend-box.svg | 6 +++--- .../time-series-and-polygon-key-glyphs.svg | 6 +++--- tests/figs/scales-breaks-and-labels/functional-limits.svg | 6 +++--- 11 files changed, 31 insertions(+), 31 deletions(-) diff --git a/tests/figs/geom-violin/dodging-and-coord-flip.svg b/tests/figs/geom-violin/dodging-and-coord-flip.svg index b45e5a0e65..13d66d5863 100644 --- a/tests/figs/geom-violin/dodging-and-coord-flip.svg +++ b/tests/figs/geom-violin/dodging-and-coord-flip.svg @@ -49,11 +49,11 @@ x - + - + - + A B C diff --git a/tests/figs/geom-violin/dodging.svg b/tests/figs/geom-violin/dodging.svg index b37ca45d19..6de498da6c 100644 --- a/tests/figs/geom-violin/dodging.svg +++ b/tests/figs/geom-violin/dodging.svg @@ -49,11 +49,11 @@ x - + - + - + A B C diff --git a/tests/figs/geom-violin/grouping-on-x-and-fill-dodge-width-0-5.svg b/tests/figs/geom-violin/grouping-on-x-and-fill-dodge-width-0-5.svg index dada178542..0bb611dbc4 100644 --- a/tests/figs/geom-violin/grouping-on-x-and-fill-dodge-width-0-5.svg +++ b/tests/figs/geom-violin/grouping-on-x-and-fill-dodge-width-0-5.svg @@ -48,9 +48,9 @@ g - + - + e f grouping on x and fill, dodge width = 0.5 diff --git a/tests/figs/geom-violin/grouping-on-x-and-fill.svg b/tests/figs/geom-violin/grouping-on-x-and-fill.svg index a9d84cbf57..5e1615e261 100644 --- a/tests/figs/geom-violin/grouping-on-x-and-fill.svg +++ b/tests/figs/geom-violin/grouping-on-x-and-fill.svg @@ -48,9 +48,9 @@ g - + - + e f grouping on x and fill diff --git a/tests/figs/guides/legend-inside-plot-bottom-left-of-legend-at-center.svg b/tests/figs/guides/legend-inside-plot-bottom-left-of-legend-at-center.svg index 5b110afb25..3ac5878494 100644 --- a/tests/figs/guides/legend-inside-plot-bottom-left-of-legend-at-center.svg +++ b/tests/figs/guides/legend-inside-plot-bottom-left-of-legend-at-center.svg @@ -49,11 +49,11 @@ x - + - + - + A B C diff --git a/tests/figs/guides/legend-inside-plot-bottom-left.svg b/tests/figs/guides/legend-inside-plot-bottom-left.svg index 05fc30a539..5a975fe381 100644 --- a/tests/figs/guides/legend-inside-plot-bottom-left.svg +++ b/tests/figs/guides/legend-inside-plot-bottom-left.svg @@ -49,11 +49,11 @@ x - + - + - + A B C diff --git a/tests/figs/guides/legend-inside-plot-centered.svg b/tests/figs/guides/legend-inside-plot-centered.svg index 21509081da..158ab3abe2 100644 --- a/tests/figs/guides/legend-inside-plot-centered.svg +++ b/tests/figs/guides/legend-inside-plot-centered.svg @@ -49,11 +49,11 @@ x - + - + - + A B C diff --git a/tests/figs/guides/legend-inside-plot-top-right.svg b/tests/figs/guides/legend-inside-plot-top-right.svg index e5d767f21b..0fe7c38b9c 100644 --- a/tests/figs/guides/legend-inside-plot-top-right.svg +++ b/tests/figs/guides/legend-inside-plot-top-right.svg @@ -49,11 +49,11 @@ x - + - + - + A B C diff --git a/tests/figs/guides/padding-in-legend-box.svg b/tests/figs/guides/padding-in-legend-box.svg index 105c8417f8..8f1ff61213 100644 --- a/tests/figs/guides/padding-in-legend-box.svg +++ b/tests/figs/guides/padding-in-legend-box.svg @@ -49,11 +49,11 @@ x - + - + - + A B C diff --git a/tests/figs/legend-key-glyphs/time-series-and-polygon-key-glyphs.svg b/tests/figs/legend-key-glyphs/time-series-and-polygon-key-glyphs.svg index 01e6331fe9..9d4ae8141d 100644 --- a/tests/figs/legend-key-glyphs/time-series-and-polygon-key-glyphs.svg +++ b/tests/figs/legend-key-glyphs/time-series-and-polygon-key-glyphs.svg @@ -59,11 +59,11 @@ z - + - + - + a b c diff --git a/tests/figs/scales-breaks-and-labels/functional-limits.svg b/tests/figs/scales-breaks-and-labels/functional-limits.svg index 5abb86fc4a..b240537285 100644 --- a/tests/figs/scales-breaks-and-labels/functional-limits.svg +++ b/tests/figs/scales-breaks-and-labels/functional-limits.svg @@ -66,11 +66,11 @@ drv - + - + - + 4 f r