diff --git a/NEWS b/NEWS index 7a8c643..22253e2 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,7 @@ * Fixed `coord_proj()` * Removed pokemon colors (et al) * Added dotted-gridline guide for `geom_dumbbell()` +* Complete parameter rewrite to 0.3.0 ===================== diff --git a/R/geom_dumbbell.R b/R/geom_dumbbell.R index 86934f3..ec64cdd 100644 --- a/R/geom_dumbbell.R +++ b/R/geom_dumbbell.R @@ -14,10 +14,10 @@ #' often aesthetics, used to set an aesthetic to a fixed value, like #' \code{color = "red"} or \code{size = 3}. They may also be parameters #' to the paired geom/stat. -#' @param point.size.l the size of the left point -#' @param point.colour.l the colour of the left point -#' @param point.size.r the size of the right point -#' @param point.colour.r the colour of the right point +#' @param size_x the size of the start point +#' @param colour_x the colour of the start point +#' @param size_xend the size of the end point +#' @param colour_xend the colour of the end point #' @param dot_guide if \code{TRUE}, a leading dotted line will be placed before the left-most dumbbell point #' @param dot_guide_size,dot_guide_color singe-value aesthetics for \code{dot_guide} #' @inheritParams ggplot2::layer @@ -29,10 +29,10 @@ #' #' ggplot(df, aes(y=trt, x=l, xend=r)) + geom_dumbbell() geom_dumbbell <- function(mapping = NULL, data = NULL, ..., - point.colour.l = NULL, point.size.l = NULL, - point.colour.r = NULL, point.size.r = NULL, + colour_x = NULL, size_x = NULL, + colour_xend = NULL, size_xend = NULL, dot_guide = FALSE, dot_guide_size = NULL, - dot_guide_color = NULL, + dot_guide_colour = NULL, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) { layer( @@ -45,13 +45,13 @@ geom_dumbbell <- function(mapping = NULL, data = NULL, ..., inherit.aes = inherit.aes, params = list( na.rm = na.rm, - point.colour.l = point.colour.l, - point.size.l = point.size.l, - point.colour.r = point.colour.r, - point.size.r = point.size.r, + colour_x = colour_x, + size_x = size_x, + colour_xend = colour_xend, + size_xend = size_xend, dot_guide = dot_guide, dot_guide_size = dot_guide_size, - dot_guide_color = dot_guide_color, + dot_guide_colour = dot_guide_colour, ... ) ) @@ -64,9 +64,9 @@ geom_dumbbell <- function(mapping = NULL, data = NULL, ..., GeomDumbbell <- ggproto("GeomDumbbell", Geom, required_aes = c("x", "xend", "y"), non_missing_aes = c("size", "shape", - "point.colour.l", "point.size.l", - "point.colour.r", "point.size.r", - "dot_guide", "dot_guide_size", "dot_guide_color"), + "colour_x", "size_x", + "colour_xend", "size_xend", + "dot_guide", "dot_guide_size", "dot_guide_colour"), default_aes = aes( shape = 19, colour = "black", size = 0.5, fill = NA, alpha = NA, stroke = 0.5 @@ -77,33 +77,35 @@ GeomDumbbell <- ggproto("GeomDumbbell", Geom, }, draw_group = function(data, panel_scales, coord, - point.colour.l = NULL, point.size.l = NULL, - point.colour.r = NULL, point.size.r = NULL, + colour_x = NULL, size_x = NULL, + colour_xend = NULL, size_xend = NULL, dot_guide = NULL, dot_guide_size = NULL, - dot_guide_color = NULL) { + dot_guide_colour = NULL) { - points.l <- data - points.l$colour <- point.colour.l %||% data$colour - points.l$size <- point.size.l %||% (data$size * 1.2) + points.x <- data + points.x$colour <- colour_x %||% data$colour + points.x$xend <- NULL + points.x$size <- size_x %||% (data$size * 1.2) - points.r <- data - points.r$x <- points.r$xend - points.r$colour <- point.colour.r %||% data$colour - points.r$size <- point.size.r %||% (data$size * 1.25) + points.xend <- data + points.xend$x <- points.xend$xend + points.xend$xend <- NULL + points.xend$colour <- colour_xend %||% data$colour + points.xend$size <- size_xend %||% (data$size * 1.25) dot_df <- data dot_df$xend <- ifelse(data$xend < data$x, data$xend, data$x) dot_df$x <- -Inf dot_df$linetype <- "11" dot_df$size <- dot_guide_size %||% (data$size * 0.5) - dot_df$color <- dot_guide_color %||% "#5b5b5b" + dot_df$colour <- dot_guide_colour %||% "#5b5b5b" if (is.null(dot_guide) | !dot_guide) { gList( ggplot2::GeomSegment$draw_panel(data, panel_scales, coord), - ggplot2::GeomPoint$draw_panel(points.l, panel_scales, coord), - ggplot2::GeomPoint$draw_panel(points.r, panel_scales, coord) + ggplot2::GeomPoint$draw_panel(points.x, panel_scales, coord), + ggplot2::GeomPoint$draw_panel(points.xend, panel_scales, coord) ) } else { @@ -111,8 +113,8 @@ GeomDumbbell <- ggproto("GeomDumbbell", Geom, gList( ggplot2::GeomSegment$draw_panel(dot_df, panel_scales, coord), ggplot2::GeomSegment$draw_panel(data, panel_scales, coord), - ggplot2::GeomPoint$draw_panel(points.l, panel_scales, coord), - ggplot2::GeomPoint$draw_panel(points.r, panel_scales, coord) + ggplot2::GeomPoint$draw_panel(points.x, panel_scales, coord), + ggplot2::GeomPoint$draw_panel(points.xend, panel_scales, coord) ) } diff --git a/README.Rmd b/README.Rmd index 2123c16..ceb3f9a 100644 --- a/README.Rmd +++ b/README.Rmd @@ -19,7 +19,7 @@ A compendium of 'geoms', 'coords', 'stats', scales and fonts for 'ggplot2', incl The following functions are implemented: -- `coord_proj` : Like `coord_map`, only better 😜 (prbly shld use this with `geom_cartogram` as `geom_map`'s new defaults are ugh) +- `coord_proj` : Like `coord_map`, only better (prbly shld use this with `geom_cartogram` as `geom_map`'s new defaults are ugh) - `geom_xspline` : Connect control points/observations with an X-spline - `stat_xspline` : Connect control points/observations with an X-spline - `geom_bkde` : Display a smooth density estimate (uses `KernSmooth::bkde`) @@ -284,7 +284,7 @@ library(ggalt) library(scales) gg <- ggplot(df, aes(y=reorder(category, pct), x=pct)) -gg <- gg + geom_lollipop(point.colour="steelblue", point.size=3, horizontal=TRUE) +gg <- gg + geom_lollipop(point.colour="steelblue", point.size=2, horizontal=TRUE) gg <- gg + scale_x_continuous(expand=c(0,0), labels=percent, breaks=seq(0, 1, by=0.2), limits=c(0, 1)) gg <- gg + labs(x=NULL, y=NULL, @@ -295,7 +295,7 @@ gg <- gg + theme_minimal(base_family="Arial Narrow") gg <- gg + theme(panel.grid.major.y=element_blank()) gg <- gg + theme(panel.grid.minor=element_blank()) gg <- gg + theme(axis.line.y=element_line(color="#2b2b2b", size=0.15)) -gg <- gg + theme(axis.text.y=element_text(margin=margin(r=-5, l=0))) +gg <- gg + theme(axis.text.y=element_text(margin=margin(r=0, l=0))) gg <- gg + theme(plot.margin=unit(rep(30, 4), "pt")) gg <- gg + theme(plot.title=element_text(face="bold")) gg <- gg + theme(plot.subtitle=element_text(margin=margin(b=10))) @@ -326,9 +326,9 @@ health %>% setNames(bind_cols(filter(health, year==2014), filter(health, year==2013))[,c(4,1,5)], c("area_name", "pct_2014", "pct_2013")) -> health - -gg <- ggplot(health, aes(x=pct_2013, xend=pct_2014, y=area_name, group=area_name)) -gg <- gg + geom_dumbbell(color="#a3c4dc", size=0.75, point.colour.l="#0e668b") +gg <- ggplot(health, aes(x=pct_2014, xend=pct_2013, y=area_name, group=area_name)) +gg <- gg + geom_dumbbell(colour="#a3c4dc", size=1.5, colour_xend="#0e668b", + dot_guide=TRUE, dot_guide_size=0.15) gg <- gg + scale_x_continuous(label=percent) gg <- gg + labs(x=NULL, y=NULL) gg <- gg + theme_bw() @@ -350,8 +350,8 @@ df <- data.frame(trt=LETTERS[1:5], l=c(20, 40, 10, 30, 50), r=c(70, 50, 30, 60, ggplot(df, aes(y=trt, x=l, xend=r)) + geom_dumbbell(size=3, color="#e3e2e1", - point.colour.l = "#5b8124", point.colour.r = "#bad744", - dot_guide=TRUE, dot_guide_size=0.75) + + colour_x = "#5b8124", colour_xend = "#bad744", + dot_guide=TRUE, dot_guide_size=0.25) + labs(x=NULL, y=NULL, title="ggplot2 geom_dumbbell with dot guide") + theme_ipsum_rc(grid="X") + theme(panel.grid.major.x=element_line(size=0.05)) diff --git a/README.md b/README.md index 9d5c447..b5dd903 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ A compendium of 'geoms', 'coords', 'stats', scales and fonts for 'ggplot2', incl The following functions are implemented: -- `coord_proj` : Like `coord_map`, only better 😜 (prbly shld use this with `geom_cartogram` as `geom_map`'s new defaults are ugh) +- `coord_proj` : Like `coord_map`, only better (prbly shld use this with `geom_cartogram` as `geom_map`'s new defaults are ugh) - `geom_xspline` : Connect control points/observations with an X-spline - `stat_xspline` : Connect control points/observations with an X-spline - `geom_bkde` : Display a smooth density estimate (uses `KernSmooth::bkde`) -- `geom_stateface`: Use ProPublica's StateFace font in ggplot2 plots- `stat_bkde` : Display a smooth density estimate (uses `KernSmooth::bkde`) @@ -407,7 +407,7 @@ library(ggalt) library(scales) gg <- ggplot(df, aes(y=reorder(category, pct), x=pct)) -gg <- gg + geom_lollipop(point.colour="steelblue", point.size=3, horizontal=TRUE) +gg <- gg + geom_lollipop(point.colour="steelblue", point.size=2, horizontal=TRUE) gg <- gg + scale_x_continuous(expand=c(0,0), labels=percent, breaks=seq(0, 1, by=0.2), limits=c(0, 1)) gg <- gg + labs(x=NULL, y=NULL, @@ -418,7 +418,7 @@ gg <- gg + theme_minimal(base_family="Arial Narrow") gg <- gg + theme(panel.grid.major.y=element_blank()) gg <- gg + theme(panel.grid.minor=element_blank()) gg <- gg + theme(axis.line.y=element_line(color="#2b2b2b", size=0.15)) -gg <- gg + theme(axis.text.y=element_text(margin=margin(r=-5, l=0))) +gg <- gg + theme(axis.text.y=element_text(margin=margin(r=0, l=0))) gg <- gg + theme(plot.margin=unit(rep(30, 4), "pt")) gg <- gg + theme(plot.title=element_text(face="bold")) gg <- gg + theme(plot.subtitle=element_text(margin=margin(b=10))) @@ -451,9 +451,9 @@ health %>% setNames(bind_cols(filter(health, year==2014), filter(health, year==2013))[,c(4,1,5)], c("area_name", "pct_2014", "pct_2013")) -> health - -gg <- ggplot(health, aes(x=pct_2013, xend=pct_2014, y=area_name, group=area_name)) -gg <- gg + geom_dumbbell(color="#a3c4dc", size=0.75, point.colour.l="#0e668b") +gg <- ggplot(health, aes(x=pct_2014, xend=pct_2013, y=area_name, group=area_name)) +gg <- gg + geom_dumbbell(colour="#a3c4dc", size=1.5, colour_xend="#0e668b", + dot_guide=TRUE, dot_guide_size=0.15) gg <- gg + scale_x_continuous(label=percent) gg <- gg + labs(x=NULL, y=NULL) gg <- gg + theme_bw() @@ -477,8 +477,8 @@ df <- data.frame(trt=LETTERS[1:5], l=c(20, 40, 10, 30, 50), r=c(70, 50, 30, 60, ggplot(df, aes(y=trt, x=l, xend=r)) + geom_dumbbell(size=3, color="#e3e2e1", - point.colour.l = "#5b8124", point.colour.r = "#bad744", - dot_guide=TRUE, dot_guide_size=0.75) + + colour_x = "#5b8124", colour_xend = "#bad744", + dot_guide=TRUE, dot_guide_size=0.25) + labs(x=NULL, y=NULL, title="ggplot2 geom_dumbbell with dot guide") + theme_ipsum_rc(grid="X") + theme(panel.grid.major.x=element_line(size=0.05)) diff --git a/README_figs/README-dumbbell-1.png b/README_figs/README-dumbbell-1.png index bc05435..ded0da2 100644 Binary files a/README_figs/README-dumbbell-1.png and b/README_figs/README-dumbbell-1.png differ diff --git a/README_figs/README-dumbbell2-1.png b/README_figs/README-dumbbell2-1.png index b86b355..b43f872 100644 Binary files a/README_figs/README-dumbbell2-1.png and b/README_figs/README-dumbbell2-1.png differ diff --git a/README_figs/README-lollipop-1.png b/README_figs/README-lollipop-1.png index f03c97a..3462931 100644 Binary files a/README_figs/README-lollipop-1.png and b/README_figs/README-lollipop-1.png differ diff --git a/man/geom_dumbbell.Rd b/man/geom_dumbbell.Rd index 0a8e9cd..b5f0a38 100644 --- a/man/geom_dumbbell.Rd +++ b/man/geom_dumbbell.Rd @@ -4,9 +4,9 @@ \alias{geom_dumbbell} \title{Dumbell charts} \usage{ -geom_dumbbell(mapping = NULL, data = NULL, ..., point.colour.l = NULL, - point.size.l = NULL, point.colour.r = NULL, point.size.r = NULL, - dot_guide = FALSE, dot_guide_size = NULL, dot_guide_color = NULL, +geom_dumbbell(mapping = NULL, data = NULL, ..., colour_x = NULL, + size_x = NULL, colour_xend = NULL, size_xend = NULL, + dot_guide = FALSE, dot_guide_size = NULL, dot_guide_colour = NULL, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) } \arguments{ @@ -34,13 +34,13 @@ often aesthetics, used to set an aesthetic to a fixed value, like \code{color = "red"} or \code{size = 3}. They may also be parameters to the paired geom/stat.} -\item{point.colour.l}{the colour of the left point} +\item{colour_x}{the colour of the start point} -\item{point.size.l}{the size of the left point} +\item{size_x}{the size of the start point} -\item{point.colour.r}{the colour of the right point} +\item{colour_xend}{the colour of the end point} -\item{point.size.r}{the size of the right point} +\item{size_xend}{the size of the end point} \item{dot_guide}{if \code{TRUE}, a leading dotted line will be placed before the left-most dumbbell point}