Browse Source

geom_dumbbell

pull/15/head
boB Rudis 8 years ago
parent
commit
f098516c60
  1. 1
      DESCRIPTION
  2. 2
      NAMESPACE
  3. 101
      R/geom_dumbbell.R
  4. 41
      README.Rmd
  5. 573
      README.html
  6. 532
      README.md
  7. BIN
      README_figs/README-coord_proj-1.png
  8. BIN
      README_figs/README-dumbbell-1.png
  9. BIN
      README_figs/README-stateface-1.png
  10. BIN
      Rplot.png
  11. 80
      man/geom_dumbbell.Rd
  12. 3
      man/ggalt-ggproto.Rd

1
DESCRIPTION

@ -62,6 +62,7 @@ Collate:
'ggalt-package.r' 'ggalt-package.r'
'grob_absolute.r' 'grob_absolute.r'
'geom_lollipop.r' 'geom_lollipop.r'
'geom_dumbbell.R'
'guide_axis.r' 'guide_axis.r'
'pokemon.r' 'pokemon.r'
'stateface.r' 'stateface.r'

2
NAMESPACE

@ -9,6 +9,7 @@ export(CoordProj)
export(Gb) export(Gb)
export(GeomBkde) export(GeomBkde)
export(GeomBkde2d) export(GeomBkde2d)
export(GeomDumbbell)
export(GeomEncircle) export(GeomEncircle)
export(GeomLollipop) export(GeomLollipop)
export(GeomStateface) export(GeomStateface)
@ -26,6 +27,7 @@ export(bytes)
export(coord_proj) export(coord_proj)
export(geom_bkde) export(geom_bkde)
export(geom_bkde2d) export(geom_bkde2d)
export(geom_dumbbell)
export(geom_encircle) export(geom_encircle)
export(geom_lollipop) export(geom_lollipop)
export(geom_stateface) export(geom_stateface)

101
R/geom_dumbbell.R

@ -0,0 +1,101 @@
#' Dumbell charts
#'
#' The dumbbell geom is used to create dumbbell charts.
#'
#' Dumbbell dot plots — dot plots with two or more series of data — are an
#' alternative to the clustered bar chart or slope graph.\cr
#' \cr
#' Use these dot plots to visualize two or three different points in time. Or,
#' use them to triangulate different viewpoints (e.g., one dot for Republicans
#' and another dot for Democrats, or one dot for principals and another dot for
#' teachers).
#'
#' @section Aesthetics:
#' \Sexpr[results=rd,stage=build]{ggplot2:::rd_aesthetics("geom", "point")}
#' @inheritParams ggplot2::layer
#' @param na.rm If \code{FALSE} (the default), removes missing values with
#' a warning. If \code{TRUE} silently removes missing values.
#' @param ... other arguments passed on to \code{\link{layer}}. These are
#' 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
#' @inheritParams ggplot2::layer
#' @export
#' @examples
#' df <- data.frame(trt=LETTERS[1:10],
#' value=seq(100, 10, by=-10))
#'
#' ggplot(df, aes(trt, value)) + geom_lollipop()
#'
#' ggplot(df, aes(value, trt)) + geom_lollipop(horizontal=TRUE)
geom_dumbbell <- function(mapping = NULL, data = NULL, ...,
point.colour.l = NULL, point.size.l = NULL,
point.colour.r = NULL, point.size.r = NULL,
na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
stat = "identity",
geom = GeomDumbbell,
position = "identity",
show.legend = show.legend,
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,
...
)
)
}
#' @rdname ggalt-ggproto
#' @format NULL
#' @usage NULL
#' @export
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"),
default_aes = aes(
shape = 19, colour = "black", size = 0.5, fill = NA,
alpha = NA, stroke = 0.5
),
setup_data = function(data, params) {
transform(data, yend = y)
},
draw_group = function(data, panel_scales, coord,
point.colour.l = NULL, point.size.l = NULL,
point.colour.r = NULL, point.size.r = NULL) {
points.r <- data
points.r$colour <- point.colour.r %||% data$colour
points.r$size <- point.size.r %||% (data$size * 2.5)
points.l <- data
points.l$x <- points.l$xend
points.l$colour <- point.colour.l %||% data$colour
points.l$size <- point.size.l %||% (data$size * 2.5)
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)
)
},
draw_key = draw_key_point
)

41
README.Rmd

@ -40,6 +40,7 @@ The following functions are implemented:
- `scale_fill_pokemon` : discrete pokemon scales (data taken from the hard work by the <http://www.pokegraphs.com/>) - `scale_fill_pokemon` : discrete pokemon scales (data taken from the hard work by the <http://www.pokegraphs.com/>)
- `byte_format`: + helpers. e.g. turn `10000` into `10 Kb` - `byte_format`: + helpers. e.g. turn `10000` into `10 Kb`
- `geom_lollipop()`: Dead easy lollipops (horizontal or vertical) - `geom_lollipop()`: Dead easy lollipops (horizontal or vertical)
- `geom_dumbberll()` : Dead easy dumbbell plots
### Installation ### Installation
@ -290,6 +291,46 @@ gg <- gg + theme(plot.caption=element_text(size=8, margin=margin(t=10)))
gg gg
``` ```
```{r dumbbell}
library(dplyr)
library(tidyr)
library(scales)
library(ggplot2)
library(ggalt) # devtools::install_github("hrbrmstr/ggalt")
health <- read.csv("https://gist.githubusercontent.com/hrbrmstr/0d206070cea01bcb0118/raw/0ea32190a8b2f54b5a9770cb6582007132571c98/zhealth.csv", stringsAsFactors=FALSE,
header=FALSE, col.names=c("pct", "area_id"))
areas <- read.csv("https://gist.githubusercontent.com/hrbrmstr/0d206070cea01bcb0118/raw/0ea32190a8b2f54b5a9770cb6582007132571c98/zarea_trans.csv", stringsAsFactors=FALSE, header=TRUE)
health %>%
mutate(area_id=trunc(area_id)) %>%
arrange(area_id, pct) %>%
mutate(year=rep(c("2014", "2013"), 26),
pct=pct/100) %>%
left_join(areas, "area_id") %>%
mutate(area_name=factor(area_name, levels=unique(area_name))) -> 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 <- gg + scale_x_continuous(label=percent)
gg <- gg + labs(x=NULL, y=NULL)
gg <- gg + theme_bw()
gg <- gg + theme(plot.background=element_rect(fill="#f7f7f7"))
gg <- gg + theme(panel.background=element_rect(fill="#f7f7f7"))
gg <- gg + theme(panel.grid.minor=element_blank())
gg <- gg + theme(panel.grid.major.y=element_blank())
gg <- gg + theme(panel.grid.major.x=element_line())
gg <- gg + theme(axis.ticks=element_blank())
gg <- gg + theme(legend.position="top")
gg <- gg + theme(panel.border=element_blank())
gg
```
### Code of Conduct ### Code of Conduct
Please note that this project is released with a [Contributor Code of Conduct](CONDUCT.md). Please note that this project is released with a [Contributor Code of Conduct](CONDUCT.md).

573
README.html

File diff suppressed because one or more lines are too long

532
README.md

@ -26,6 +26,7 @@ The following functions are implemented:
- `scale_fill_pokemon` : discrete pokemon scales (data taken from the hard work by the <http://www.pokegraphs.com/>) - `scale_fill_pokemon` : discrete pokemon scales (data taken from the hard work by the <http://www.pokegraphs.com/>)
- `byte_format`: + helpers. e.g. turn `10000` into `10 Kb` - `byte_format`: + helpers. e.g. turn `10000` into `10 Kb`
- `geom_lollipop()`: Dead easy lollipops (horizontal or vertical) - `geom_lollipop()`: Dead easy lollipops (horizontal or vertical)
- `geom_dumbberll()` : Dead easy dumbbell plots
### Installation ### Installation
@ -67,7 +68,7 @@ ggplot(dat, aes(x, y, group=group, color=group)) +
geom_line() geom_line()
``` ```
<img src="README_figs/README-splines-1.png" title="" alt="" width="672" /> <img src="README_figs/README-splines-1.png" width="672" />
```r ```r
@ -77,7 +78,7 @@ ggplot(dat, aes(x, y, group=group, color=factor(group))) +
geom_smooth(se=FALSE, linetype="dashed", size=0.5) geom_smooth(se=FALSE, linetype="dashed", size=0.5)
``` ```
<img src="README_figs/README-splines-2.png" title="" alt="" width="672" /> <img src="README_figs/README-splines-2.png" width="672" />
```r ```r
@ -87,7 +88,7 @@ ggplot(dat, aes(x, y, group=group, color=factor(group))) +
geom_xspline(size=0.5) geom_xspline(size=0.5)
``` ```
<img src="README_figs/README-splines-3.png" title="" alt="" width="672" /> <img src="README_figs/README-splines-3.png" width="672" />
```r ```r
@ -97,7 +98,7 @@ ggplot(dat, aes(x, y, group=group, color=factor(group))) +
geom_xspline(spline_shape=-0.4, size=0.5) geom_xspline(spline_shape=-0.4, size=0.5)
``` ```
<img src="README_figs/README-splines-4.png" title="" alt="" width="672" /> <img src="README_figs/README-splines-4.png" width="672" />
```r ```r
@ -107,7 +108,7 @@ ggplot(dat, aes(x, y, group=group, color=factor(group))) +
geom_xspline(spline_shape=0.4, size=0.5) geom_xspline(spline_shape=0.4, size=0.5)
``` ```
<img src="README_figs/README-splines-5.png" title="" alt="" width="672" /> <img src="README_figs/README-splines-5.png" width="672" />
```r ```r
@ -117,7 +118,7 @@ ggplot(dat, aes(x, y, group=group, color=factor(group))) +
geom_xspline(spline_shape=1, size=0.5) geom_xspline(spline_shape=1, size=0.5)
``` ```
<img src="README_figs/README-splines-6.png" title="" alt="" width="672" /> <img src="README_figs/README-splines-6.png" width="672" />
```r ```r
@ -127,7 +128,7 @@ ggplot(dat, aes(x, y, group=group, color=factor(group))) +
geom_xspline(spline_shape=0, size=0.5) geom_xspline(spline_shape=0, size=0.5)
``` ```
<img src="README_figs/README-splines-7.png" title="" alt="" width="672" /> <img src="README_figs/README-splines-7.png" width="672" />
```r ```r
@ -137,7 +138,7 @@ ggplot(dat, aes(x, y, group=group, color=factor(group))) +
geom_xspline(spline_shape=-1, size=0.5) geom_xspline(spline_shape=-1, size=0.5)
``` ```
<img src="README_figs/README-splines-8.png" title="" alt="" width="672" /> <img src="README_figs/README-splines-8.png" width="672" />
#### Alternate (better) density plots #### Alternate (better) density plots
@ -152,7 +153,7 @@ ggplot(geyser, aes(x=duration)) +
#> Bandwidth not specified. Using '0.14', via KernSmooth::dpik. #> Bandwidth not specified. Using '0.14', via KernSmooth::dpik.
``` ```
<img src="README_figs/README-bkde_ash-1.png" title="" alt="" width="672" /> <img src="README_figs/README-bkde_ash-1.png" width="672" />
```r ```r
@ -161,7 +162,7 @@ ggplot(geyser, aes(x=duration)) +
#> Bandwidth not specified. Using '0.14', via KernSmooth::dpik. #> Bandwidth not specified. Using '0.14', via KernSmooth::dpik.
``` ```
<img src="README_figs/README-bkde_ash-2.png" title="" alt="" width="672" /> <img src="README_figs/README-bkde_ash-2.png" width="672" />
```r ```r
@ -169,7 +170,7 @@ ggplot(geyser, aes(x=duration)) +
stat_bkde(bandwidth=0.25) stat_bkde(bandwidth=0.25)
``` ```
<img src="README_figs/README-bkde_ash-3.png" title="" alt="" width="672" /> <img src="README_figs/README-bkde_ash-3.png" width="672" />
```r ```r
@ -177,7 +178,7 @@ ggplot(geyser, aes(x=duration)) +
geom_bkde(bandwidth=0.25) geom_bkde(bandwidth=0.25)
``` ```
<img src="README_figs/README-bkde_ash-4.png" title="" alt="" width="672" /> <img src="README_figs/README-bkde_ash-4.png" width="672" />
```r ```r
@ -190,7 +191,7 @@ ggplot(dat, aes(x=rating, color=cond)) + geom_bkde(fill="#00000000")
#> Bandwidth not specified. Using '0.31', via KernSmooth::dpik. #> Bandwidth not specified. Using '0.31', via KernSmooth::dpik.
``` ```
<img src="README_figs/README-bkde_ash-5.png" title="" alt="" width="672" /> <img src="README_figs/README-bkde_ash-5.png" width="672" />
```r ```r
@ -199,7 +200,7 @@ ggplot(dat, aes(x=rating, fill=cond)) + geom_bkde(alpha=0.3)
#> Bandwidth not specified. Using '0.31', via KernSmooth::dpik. #> Bandwidth not specified. Using '0.31', via KernSmooth::dpik.
``` ```
<img src="README_figs/README-bkde_ash-6.png" title="" alt="" width="672" /> <img src="README_figs/README-bkde_ash-6.png" width="672" />
```r ```r
@ -215,7 +216,7 @@ grid.arrange(ggplot(dat, aes(x)) + stat_ash(),
#> Bandwidth not specified. Using '0.43', via KernSmooth::dpik. #> Bandwidth not specified. Using '0.43', via KernSmooth::dpik.
``` ```
<img src="README_figs/README-bkde_ash-7.png" title="" alt="" width="672" /> <img src="README_figs/README-bkde_ash-7.png" width="672" />
```r ```r
@ -234,7 +235,7 @@ ggplot(dat, aes(x)) +
#> Bandwidth not specified. Using '0.43', via KernSmooth::dpik. #> Bandwidth not specified. Using '0.43', via KernSmooth::dpik.
``` ```
<img src="README_figs/README-bkde_ash-8.png" title="" alt="" width="672" /> <img src="README_figs/README-bkde_ash-8.png" width="672" />
### Alternate 2D density plots ### Alternate 2D density plots
@ -248,14 +249,14 @@ m <- ggplot(faithful, aes(x = eruptions, y = waiting)) +
m + geom_bkde2d(bandwidth=c(0.5, 4)) m + geom_bkde2d(bandwidth=c(0.5, 4))
``` ```
<img src="README_figs/README-bkde2d-1.png" title="" alt="" width="672" /> <img src="README_figs/README-bkde2d-1.png" width="672" />
```r ```r
m + stat_bkde2d(bandwidth=c(0.5, 4), aes(fill = ..level..), geom = "polygon") m + stat_bkde2d(bandwidth=c(0.5, 4), aes(fill = ..level..), geom = "polygon")
``` ```
<img src="README_figs/README-bkde2d-2.png" title="" alt="" width="672" /> <img src="README_figs/README-bkde2d-2.png" width="672" />
### `coord_proj` LIVES! (still needs a teensy bit of work) ### `coord_proj` LIVES! (still needs a teensy bit of work)
@ -263,8 +264,9 @@ m + stat_bkde2d(bandwidth=c(0.5, 4), aes(fill = ..level..), geom = "polygon")
```r ```r
world <- map_data("world") world <- map_data("world")
#> #>
#> # maps v3.1: updated 'world': all lakes moved to separate new # #> # ATTENTION: maps v3.0 has an updated 'world' map. #
#> # 'lakes' database. Type '?world' or 'news(package="maps")'. # #> # Many country borders and names have changed since 1990. #
#> # Type '?world' or 'news(package="maps")'. See README_v3. #
world <- world[world$region != "Antarctica",] world <- world[world$region != "Antarctica",]
gg <- ggplot() gg <- ggplot()
@ -274,7 +276,7 @@ gg <- gg + coord_proj("+proj=wintri")
gg gg
``` ```
<img src="README_figs/README-coord_proj-1.png" title="" alt="" width="672" /> <img src="README_figs/README-coord_proj-1.png" width="672" />
### ProPublica StateFace ### ProPublica StateFace
@ -295,9 +297,428 @@ gg <- gg + geom_stateface(aes(label=state, color=col, size=sz))
gg <- gg + scale_color_identity() gg <- gg + scale_color_identity()
gg <- gg + scale_size_identity() gg <- gg + scale_size_identity()
gg gg
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
#> Warning in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : no font could be found for family
#> "StateFace"
``` ```
<img src="README_figs/README-stateface-1.png" title="" alt="" width="672" /> <img src="README_figs/README-stateface-1.png" width="672" />
### Encircling points automagically ### Encircling points automagically
@ -312,21 +733,21 @@ gg <- gg + scale_y_continuous(expand=c(0.5,1))
gg + geom_encircle(s_shape=1, expand=0) + geom_point() gg + geom_encircle(s_shape=1, expand=0) + geom_point()
``` ```
<img src="README_figs/README-encircle-1.png" title="" alt="" width="672" /> <img src="README_figs/README-encircle-1.png" width="672" />
```r ```r
gg + geom_encircle(s_shape=1, expand=0.1, colour="red") + geom_point() gg + geom_encircle(s_shape=1, expand=0.1, colour="red") + geom_point()
``` ```
<img src="README_figs/README-encircle-2.png" title="" alt="" width="672" /> <img src="README_figs/README-encircle-2.png" width="672" />
```r ```r
gg + geom_encircle(s_shape=0.5, expand=0.1, colour="purple") + geom_point() gg + geom_encircle(s_shape=0.5, expand=0.1, colour="purple") + geom_point()
``` ```
<img src="README_figs/README-encircle-3.png" title="" alt="" width="672" /> <img src="README_figs/README-encircle-3.png" width="672" />
```r ```r
@ -334,7 +755,7 @@ gg + geom_encircle(data=subset(d, x==1), colour="blue", spread=0.02) +
geom_point() geom_point()
``` ```
<img src="README_figs/README-encircle-4.png" title="" alt="" width="672" /> <img src="README_figs/README-encircle-4.png" width="672" />
```r ```r
@ -342,7 +763,7 @@ gg +geom_encircle(data=subset(d, x==2), colour="cyan", spread=0.04) +
geom_point() geom_point()
``` ```
<img src="README_figs/README-encircle-5.png" title="" alt="" width="672" /> <img src="README_figs/README-encircle-5.png" width="672" />
```r ```r
@ -350,7 +771,7 @@ gg <- ggplot(mpg, aes(displ, hwy))
gg + geom_encircle(data=subset(mpg, hwy>40)) + geom_point() gg + geom_encircle(data=subset(mpg, hwy>40)) + geom_point()
``` ```
<img src="README_figs/README-encircle-6.png" title="" alt="" width="672" /> <img src="README_figs/README-encircle-6.png" width="672" />
```r ```r
@ -360,7 +781,7 @@ gg + geom_encircle(data=ss, colour="blue", s_shape=0.9, expand=0.07) +
geom_point() + geom_point(data=ss, colour="blue") geom_point() + geom_point(data=ss, colour="blue")
``` ```
<img src="README_figs/README-encircle-7.png" title="" alt="" width="672" /> <img src="README_figs/README-encircle-7.png" width="672" />
### Lollipop charts ### Lollipop charts
@ -413,7 +834,58 @@ gg <- gg + theme(plot.caption=element_text(size=8, margin=margin(t=10)))
gg gg
``` ```
<img src="README_figs/README-lollipop-1.png" title="" alt="" width="672" /> <img src="README_figs/README-lollipop-1.png" width="672" />
```r
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(tidyr)
library(scales)
library(ggplot2)
library(ggalt) # devtools::install_github("hrbrmstr/ggalt")
health <- read.csv("https://gist.githubusercontent.com/hrbrmstr/0d206070cea01bcb0118/raw/0ea32190a8b2f54b5a9770cb6582007132571c98/zhealth.csv", stringsAsFactors=FALSE,
header=FALSE, col.names=c("pct", "area_id"))
areas <- read.csv("https://gist.githubusercontent.com/hrbrmstr/0d206070cea01bcb0118/raw/0ea32190a8b2f54b5a9770cb6582007132571c98/zarea_trans.csv", stringsAsFactors=FALSE, header=TRUE)
health %>%
mutate(area_id=trunc(area_id)) %>%
arrange(area_id, pct) %>%
mutate(year=rep(c("2014", "2013"), 26),
pct=pct/100) %>%
left_join(areas, "area_id") %>%
mutate(area_name=factor(area_name, levels=unique(area_name))) -> 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 <- gg + scale_x_continuous(label=percent)
gg <- gg + labs(x=NULL, y=NULL)
gg <- gg + theme_bw()
gg <- gg + theme(plot.background=element_rect(fill="#f7f7f7"))
gg <- gg + theme(panel.background=element_rect(fill="#f7f7f7"))
gg <- gg + theme(panel.grid.minor=element_blank())
gg <- gg + theme(panel.grid.major.y=element_blank())
gg <- gg + theme(panel.grid.major.x=element_line())
gg <- gg + theme(axis.ticks=element_blank())
gg <- gg + theme(legend.position="top")
gg <- gg + theme(panel.border=element_blank())
gg
```
<img src="README_figs/README-dumbbell-1.png" width="672" />
### Code of Conduct ### Code of Conduct

BIN
README_figs/README-coord_proj-1.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 182 KiB

After

Width:  |  Height:  |  Size: 183 KiB

BIN
README_figs/README-dumbbell-1.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 121 KiB

BIN
README_figs/README-stateface-1.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 112 KiB

After

Width:  |  Height:  |  Size: 38 KiB

BIN
Rplot.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

80
man/geom_dumbbell.Rd

@ -0,0 +1,80 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/geom_dumbbell.R
\name{geom_dumbbell}
\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,
na.rm = FALSE, show.legend = NA, inherit.aes = TRUE)
}
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
default), it is combined with the default mapping at the top level of the
plot. You must supply \code{mapping} if there is no plot mapping.}
\item{data}{The data to be displayed in this layer. There are three
options:
If \code{NULL}, the default, the data is inherited from the plot
data as specified in the call to \code{\link{ggplot}}.
A \code{data.frame}, or other object, will override the plot
data. All objects will be fortified to produce a data frame. See
\code{\link{fortify}} for which variables will be created.
A \code{function} will be called with a single argument,
the plot data. The return value must be a \code{data.frame.}, and
will be used as the layer data.}
\item{...}{other arguments passed on to \code{\link{layer}}. These are
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{point.size.l}{the size of the left point}
\item{point.colour.r}{the colour of the right point}
\item{point.size.r}{the size of the right point}
\item{na.rm}{If \code{FALSE} (the default), removes missing values with
a warning. If \code{TRUE} silently removes missing values.}
\item{show.legend}{logical. Should this layer be included in the legends?
\code{NA}, the default, includes if any aesthetics are mapped.
\code{FALSE} never includes, and \code{TRUE} always includes.}
\item{inherit.aes}{If \code{FALSE}, overrides the default aesthetics,
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}}.}
}
\description{
The dumbbell geom is used to create dumbbell charts.
}
\details{
Dumbbell dot plots — dot plots with two or more series of data — are an
alternative to the clustered bar chart or slope graph.\cr
\cr
Use these dot plots to visualize two or three different points in time. Or,
use them to triangulate different viewpoints (e.g., one dot for Republicans
and another dot for Democrats, or one dot for principals and another dot for
teachers).
}
\section{Aesthetics}{
\Sexpr[results=rd,stage=build]{ggplot2:::rd_aesthetics("geom", "point")}
}
\examples{
df <- data.frame(trt=LETTERS[1:10],
value=seq(100, 10, by=-10))
ggplot(df, aes(trt, value)) + geom_lollipop()
ggplot(df, aes(value, trt)) + geom_lollipop(horizontal=TRUE)
}

3
man/ggalt-ggproto.Rd

@ -1,10 +1,11 @@
% Generated by roxygen2: do not edit by hand % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/coord_proj.r, R/geom_ash.r, R/geom_bkde.r, R/geom_bkde2d.r, R/geom_encircle.r, R/geom_xspline.r, R/geom_xspline2.r, R/geom_lollipop.r, R/stateface.r % Please edit documentation in R/coord_proj.r, R/geom_ash.r, R/geom_bkde.r, R/geom_bkde2d.r, R/geom_encircle.r, R/geom_xspline.r, R/geom_xspline2.r, R/geom_lollipop.r, R/geom_dumbbell.R, R/stateface.r
\docType{data} \docType{data}
\name{CoordProj} \name{CoordProj}
\alias{CoordProj} \alias{CoordProj}
\alias{GeomBkde} \alias{GeomBkde}
\alias{GeomBkde2d} \alias{GeomBkde2d}
\alias{GeomDumbbell}
\alias{GeomEncircle} \alias{GeomEncircle}
\alias{GeomLollipop} \alias{GeomLollipop}
\alias{GeomStateface} \alias{GeomStateface}

Loading…
Cancel
Save