Skip to content

Commit 0d47ce7

Browse files
paleolimbotclauswilke
authored andcommitted
allow size and linetype aesthetics in geom_dotplot (#3078)
* fix #3059 * Change 'size' aesthetic to 'stroke' in geom_dotplot * code review changes for @clauswilke * one last change for code review
1 parent d208903 commit 0d47ce7

File tree

4 files changed

+122
-2
lines changed

4 files changed

+122
-2
lines changed

R/geom-dotplot.r

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@
8383
#' # Expand dot diameter
8484
#' ggplot(mtcars, aes(x = mpg)) + geom_dotplot(binwidth = 1.5, dotsize = 1.25)
8585
#'
86+
#' # Change dot fill colour, stroke width
87+
#' ggplot(mtcars, aes(x = mpg)) + geom_dotplot(binwidth = 1.5, fill = "white", stroke = 2)
88+
#'
8689
#' \donttest{
8790
#' # Examples with stacking along y axis instead of x
8891
#' ggplot(mtcars, aes(x = 1, y = mpg)) +
@@ -175,7 +178,7 @@ GeomDotplot <- ggproto("GeomDotplot", Geom,
175178
required_aes = c("x", "y"),
176179
non_missing_aes = c("size", "shape"),
177180

178-
default_aes = aes(colour = "black", fill = "black", alpha = NA),
181+
default_aes = aes(colour = "black", fill = "black", alpha = NA, stroke = 1, linetype = "solid"),
179182

180183
setup_data = function(data, params) {
181184
data$width <- data$width %||%
@@ -276,7 +279,8 @@ GeomDotplot <- ggproto("GeomDotplot", Geom,
276279
stackposition = tdata$stackpos, stackratio = stackratio,
277280
default.units = "npc",
278281
gp = gpar(col = alpha(tdata$colour, tdata$alpha),
279-
fill = alpha(tdata$fill, tdata$alpha)))
282+
fill = alpha(tdata$fill, tdata$alpha),
283+
lwd = tdata$stroke, lty = tdata$linetype))
280284
)
281285
},
282286

man/geom_dotplot.Rd

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 96 additions & 0 deletions
Loading

tests/testthat/test-geom-dotplot.R

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,21 @@ test_that("geom_dotplot draws correctly", {
177177
ggplot(dat2, aes(as.numeric(x), y)) + geom_dotplot(binwidth = .2, binaxis = "y", stackdir = "center")
178178
)
179179

180+
# border width and size
181+
expect_doppelganger(
182+
"variable linetype and size work when specified as aesthetics",
183+
ggplot(
184+
dat,
185+
aes(
186+
x,
187+
linetype = rep(c("a", "b"), length.out = nrow(dat)),
188+
stroke = rep(c(1, 2), length.out = nrow(dat))
189+
)
190+
) +
191+
geom_dotplot(binwidth = .4, fill = "red", col = "blue") +
192+
continuous_scale("stroke", "scaleName", function(x) scales::rescale(x, to = c(1, 6)))
193+
)
194+
180195
# Stacking groups
181196
expect_doppelganger("stackgroups with 3 groups, dot-density with aligned bins",
182197
ggplot(dat2, aes(y, fill = x)) + geom_dotplot(binwidth = .25, stackgroups = TRUE, binpositions = "all", alpha = 0.5)

0 commit comments

Comments
 (0)