Browse Source

more dummbell tweaks

tags/v0.4.0
boB Rudis 7 years ago
parent
commit
ee8b9977f6
  1. 1
      NEWS
  2. 62
      R/geom_dumbbell.R
  3. 16
      README.Rmd
  4. 16
      README.md
  5. BIN
      README_figs/README-dumbbell-1.png
  6. BIN
      README_figs/README-dumbbell2-1.png
  7. BIN
      README_figs/README-lollipop-1.png
  8. 14
      man/geom_dumbbell.Rd

1
NEWS

@ -3,6 +3,7 @@
* Fixed `coord_proj()` * Fixed `coord_proj()`
* Removed pokemon colors (et al) * Removed pokemon colors (et al)
* Added dotted-gridline guide for `geom_dumbbell()` * Added dotted-gridline guide for `geom_dumbbell()`
* Complete parameter rewrite to
0.3.0 0.3.0
===================== =====================

62
R/geom_dumbbell.R

@ -14,10 +14,10 @@
#' often aesthetics, used to set an aesthetic to a fixed value, like #' often aesthetics, used to set an aesthetic to a fixed value, like
#' \code{color = "red"} or \code{size = 3}. They may also be parameters #' \code{color = "red"} or \code{size = 3}. They may also be parameters
#' to the paired geom/stat. #' to the paired geom/stat.
#' @param point.size.l the size of the left point #' @param size_x the size of the start point
#' @param point.colour.l the colour of the left point #' @param colour_x the colour of the start point
#' @param point.size.r the size of the right point #' @param size_xend the size of the end point
#' @param point.colour.r the colour of the right 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 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} #' @param dot_guide_size,dot_guide_color singe-value aesthetics for \code{dot_guide}
#' @inheritParams ggplot2::layer #' @inheritParams ggplot2::layer
@ -29,10 +29,10 @@
#' #'
#' ggplot(df, aes(y=trt, x=l, xend=r)) + geom_dumbbell() #' ggplot(df, aes(y=trt, x=l, xend=r)) + geom_dumbbell()
geom_dumbbell <- function(mapping = NULL, data = NULL, ..., geom_dumbbell <- function(mapping = NULL, data = NULL, ...,
point.colour.l = NULL, point.size.l = NULL, colour_x = NULL, size_x = NULL,
point.colour.r = NULL, point.size.r = NULL, colour_xend = NULL, size_xend = NULL,
dot_guide = FALSE, dot_guide_size = 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) { na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) {
layer( layer(
@ -45,13 +45,13 @@ geom_dumbbell <- function(mapping = NULL, data = NULL, ...,
inherit.aes = inherit.aes, inherit.aes = inherit.aes,
params = list( params = list(
na.rm = na.rm, na.rm = na.rm,
point.colour.l = point.colour.l, colour_x = colour_x,
point.size.l = point.size.l, size_x = size_x,
point.colour.r = point.colour.r, colour_xend = colour_xend,
point.size.r = point.size.r, size_xend = size_xend,
dot_guide = dot_guide, dot_guide = dot_guide,
dot_guide_size = dot_guide_size, 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, GeomDumbbell <- ggproto("GeomDumbbell", Geom,
required_aes = c("x", "xend", "y"), required_aes = c("x", "xend", "y"),
non_missing_aes = c("size", "shape", non_missing_aes = c("size", "shape",
"point.colour.l", "point.size.l", "colour_x", "size_x",
"point.colour.r", "point.size.r", "colour_xend", "size_xend",
"dot_guide", "dot_guide_size", "dot_guide_color"), "dot_guide", "dot_guide_size", "dot_guide_colour"),
default_aes = aes( default_aes = aes(
shape = 19, colour = "black", size = 0.5, fill = NA, shape = 19, colour = "black", size = 0.5, fill = NA,
alpha = NA, stroke = 0.5 alpha = NA, stroke = 0.5
@ -77,33 +77,35 @@ GeomDumbbell <- ggproto("GeomDumbbell", Geom,
}, },
draw_group = function(data, panel_scales, coord, draw_group = function(data, panel_scales, coord,
point.colour.l = NULL, point.size.l = NULL, colour_x = NULL, size_x = NULL,
point.colour.r = NULL, point.size.r = NULL, colour_xend = NULL, size_xend = NULL,
dot_guide = NULL, dot_guide_size = NULL, dot_guide = NULL, dot_guide_size = NULL,
dot_guide_color = NULL) { dot_guide_colour = NULL) {
points.l <- data points.x <- data
points.l$colour <- point.colour.l %||% data$colour points.x$colour <- colour_x %||% data$colour
points.l$size <- point.size.l %||% (data$size * 1.2) points.x$xend <- NULL
points.x$size <- size_x %||% (data$size * 1.2)
points.r <- data points.xend <- data
points.r$x <- points.r$xend points.xend$x <- points.xend$xend
points.r$colour <- point.colour.r %||% data$colour points.xend$xend <- NULL
points.r$size <- point.size.r %||% (data$size * 1.25) points.xend$colour <- colour_xend %||% data$colour
points.xend$size <- size_xend %||% (data$size * 1.25)
dot_df <- data dot_df <- data
dot_df$xend <- ifelse(data$xend < data$x, data$xend, data$x) dot_df$xend <- ifelse(data$xend < data$x, data$xend, data$x)
dot_df$x <- -Inf dot_df$x <- -Inf
dot_df$linetype <- "11" dot_df$linetype <- "11"
dot_df$size <- dot_guide_size %||% (data$size * 0.5) 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) { if (is.null(dot_guide) | !dot_guide) {
gList( gList(
ggplot2::GeomSegment$draw_panel(data, 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.x, panel_scales, coord),
ggplot2::GeomPoint$draw_panel(points.r, panel_scales, coord) ggplot2::GeomPoint$draw_panel(points.xend, panel_scales, coord)
) )
} else { } else {
@ -111,8 +113,8 @@ GeomDumbbell <- ggproto("GeomDumbbell", Geom,
gList( gList(
ggplot2::GeomSegment$draw_panel(dot_df, panel_scales, coord), ggplot2::GeomSegment$draw_panel(dot_df, panel_scales, coord),
ggplot2::GeomSegment$draw_panel(data, 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.x, panel_scales, coord),
ggplot2::GeomPoint$draw_panel(points.r, panel_scales, coord) ggplot2::GeomPoint$draw_panel(points.xend, panel_scales, coord)
) )
} }

16
README.Rmd

@ -19,7 +19,7 @@ A compendium of 'geoms', 'coords', 'stats', scales and fonts for 'ggplot2', incl
The following functions are implemented: 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 - `geom_xspline` : Connect control points/observations with an X-spline
- `stat_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_bkde` : Display a smooth density estimate (uses `KernSmooth::bkde`)
@ -284,7 +284,7 @@ library(ggalt)
library(scales) library(scales)
gg <- ggplot(df, aes(y=reorder(category, pct), x=pct)) 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, gg <- gg + scale_x_continuous(expand=c(0,0), labels=percent,
breaks=seq(0, 1, by=0.2), limits=c(0, 1)) breaks=seq(0, 1, by=0.2), limits=c(0, 1))
gg <- gg + labs(x=NULL, y=NULL, 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.major.y=element_blank())
gg <- gg + theme(panel.grid.minor=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.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.margin=unit(rep(30, 4), "pt"))
gg <- gg + theme(plot.title=element_text(face="bold")) gg <- gg + theme(plot.title=element_text(face="bold"))
gg <- gg + theme(plot.subtitle=element_text(margin=margin(b=10))) 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)], setNames(bind_cols(filter(health, year==2014), filter(health, year==2013))[,c(4,1,5)],
c("area_name", "pct_2014", "pct_2013")) -> health c("area_name", "pct_2014", "pct_2013")) -> health
gg <- ggplot(health, aes(x=pct_2014, xend=pct_2013, y=area_name, group=area_name))
gg <- ggplot(health, aes(x=pct_2013, xend=pct_2014, y=area_name, group=area_name)) gg <- gg + geom_dumbbell(colour="#a3c4dc", size=1.5, colour_xend="#0e668b",
gg <- gg + geom_dumbbell(color="#a3c4dc", size=0.75, point.colour.l="#0e668b") dot_guide=TRUE, dot_guide_size=0.15)
gg <- gg + scale_x_continuous(label=percent) gg <- gg + scale_x_continuous(label=percent)
gg <- gg + labs(x=NULL, y=NULL) gg <- gg + labs(x=NULL, y=NULL)
gg <- gg + theme_bw() 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)) + ggplot(df, aes(y=trt, x=l, xend=r)) +
geom_dumbbell(size=3, color="#e3e2e1", geom_dumbbell(size=3, color="#e3e2e1",
point.colour.l = "#5b8124", point.colour.r = "#bad744", colour_x = "#5b8124", colour_xend = "#bad744",
dot_guide=TRUE, dot_guide_size=0.75) + dot_guide=TRUE, dot_guide_size=0.25) +
labs(x=NULL, y=NULL, title="ggplot2 geom_dumbbell with dot guide") + labs(x=NULL, y=NULL, title="ggplot2 geom_dumbbell with dot guide") +
theme_ipsum_rc(grid="X") + theme_ipsum_rc(grid="X") +
theme(panel.grid.major.x=element_line(size=0.05)) theme(panel.grid.major.x=element_line(size=0.05))

16
README.md

@ -8,7 +8,7 @@ A compendium of 'geoms', 'coords', 'stats', scales and fonts for 'ggplot2', incl
The following functions are implemented: 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 - `geom_xspline` : Connect control points/observations with an X-spline
- `stat_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`) - `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) library(scales)
gg <- ggplot(df, aes(y=reorder(category, pct), x=pct)) 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, gg <- gg + scale_x_continuous(expand=c(0,0), labels=percent,
breaks=seq(0, 1, by=0.2), limits=c(0, 1)) breaks=seq(0, 1, by=0.2), limits=c(0, 1))
gg <- gg + labs(x=NULL, y=NULL, 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.major.y=element_blank())
gg <- gg + theme(panel.grid.minor=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.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.margin=unit(rep(30, 4), "pt"))
gg <- gg + theme(plot.title=element_text(face="bold")) gg <- gg + theme(plot.title=element_text(face="bold"))
gg <- gg + theme(plot.subtitle=element_text(margin=margin(b=10))) 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)], setNames(bind_cols(filter(health, year==2014), filter(health, year==2013))[,c(4,1,5)],
c("area_name", "pct_2014", "pct_2013")) -> health c("area_name", "pct_2014", "pct_2013")) -> health
gg <- ggplot(health, aes(x=pct_2014, xend=pct_2013, y=area_name, group=area_name))
gg <- ggplot(health, aes(x=pct_2013, xend=pct_2014, y=area_name, group=area_name)) gg <- gg + geom_dumbbell(colour="#a3c4dc", size=1.5, colour_xend="#0e668b",
gg <- gg + geom_dumbbell(color="#a3c4dc", size=0.75, point.colour.l="#0e668b") dot_guide=TRUE, dot_guide_size=0.15)
gg <- gg + scale_x_continuous(label=percent) gg <- gg + scale_x_continuous(label=percent)
gg <- gg + labs(x=NULL, y=NULL) gg <- gg + labs(x=NULL, y=NULL)
gg <- gg + theme_bw() 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)) + ggplot(df, aes(y=trt, x=l, xend=r)) +
geom_dumbbell(size=3, color="#e3e2e1", geom_dumbbell(size=3, color="#e3e2e1",
point.colour.l = "#5b8124", point.colour.r = "#bad744", colour_x = "#5b8124", colour_xend = "#bad744",
dot_guide=TRUE, dot_guide_size=0.75) + dot_guide=TRUE, dot_guide_size=0.25) +
labs(x=NULL, y=NULL, title="ggplot2 geom_dumbbell with dot guide") + labs(x=NULL, y=NULL, title="ggplot2 geom_dumbbell with dot guide") +
theme_ipsum_rc(grid="X") + theme_ipsum_rc(grid="X") +
theme(panel.grid.major.x=element_line(size=0.05)) theme(panel.grid.major.x=element_line(size=0.05))

BIN
README_figs/README-dumbbell-1.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 107 KiB

After

Width:  |  Height:  |  Size: 120 KiB

BIN
README_figs/README-dumbbell2-1.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 35 KiB

BIN
README_figs/README-lollipop-1.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 148 KiB

After

Width:  |  Height:  |  Size: 145 KiB

14
man/geom_dumbbell.Rd

@ -4,9 +4,9 @@
\alias{geom_dumbbell} \alias{geom_dumbbell}
\title{Dumbell charts} \title{Dumbell charts}
\usage{ \usage{
geom_dumbbell(mapping = NULL, data = NULL, ..., point.colour.l = NULL, geom_dumbbell(mapping = NULL, data = NULL, ..., colour_x = NULL,
point.size.l = NULL, point.colour.r = NULL, point.size.r = NULL, size_x = NULL, colour_xend = NULL, size_xend = NULL,
dot_guide = FALSE, dot_guide_size = NULL, dot_guide_color = NULL, dot_guide = FALSE, dot_guide_size = NULL, dot_guide_colour = NULL,
na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) na.rm = FALSE, show.legend = NA, inherit.aes = TRUE)
} }
\arguments{ \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 \code{color = "red"} or \code{size = 3}. They may also be parameters
to the paired geom/stat.} 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} \item{dot_guide}{if \code{TRUE}, a leading dotted line will be placed before the left-most dumbbell point}

Loading…
Cancel
Save