Browse Source

Merge branch 'master' of github.com:hrbrmstr/ggalt

tags/v0.4.0
boB Rudis 6 years ago
parent
commit
4b35dd5d9e
  1. 2
      .Rbuildignore
  2. 15
      DESCRIPTION
  3. 3
      NAMESPACE
  4. 17
      R/coord_proj.r
  5. 37
      R/formatters.r
  6. 14
      R/geom_dumbbell.R
  7. 188
      R/geom_table.r
  8. 151
      R/geom_twoway_bar.r
  9. 2
      R/ggalt-package.r
  10. 4
      R/zzz.r
  11. 10
      README.Rmd
  12. 11
      README.md
  13. BIN
      README_figs/README-dumbbell2-1.png
  14. 17
      cran-comments.md
  15. 3
      man/byte_format.Rd
  16. 10
      man/coord_proj.Rd
  17. 14
      man/geom_dumbbell.Rd
  18. 55
      man/geom_twoway_bar.Rd
  19. 4
      man/ggalt-ggproto.Rd
  20. 265
      vignettes/ggalt_examples.Rmd

2
.Rbuildignore

@ -4,6 +4,6 @@
^README-.*\.png$
^\.travis\.yml$
^CONDUCT\.md$
^README\.Rmd$
^README_figs
^README\.html$
^cran-comments\.md$

15
DESCRIPTION

@ -5,21 +5,20 @@ Version: 0.4.0
Maintainer: Bob Rudis <bob@rud.ist>
Authors@R: c(
person("Bob", "Rudis", email = "bob@rud.is", role = c("aut", "cre")),
person("Ben", "Bolder", role = c("aut", "ctb")),
person("Jan", "Schulz", role = c("aut", "ctb")),
person("Ben", "Bolker", comment="Encircling & additional splines", role = c("aut", "ctb")),
person("Ben", "Marwick", comment="General codebase cleanup", role = c("ctb")),
person("Jan", "Schulz", comment="Annotations", role = c("aut", "ctb")),
person("Rosen", "Matev", role="ctb", comment="Original annotate_textp implementation on stackoverflow"),
person("Ingemar", role="dtc", comment="Pokémon javascript color palette"),
person("ProPublica", role="dtc", comment="StateFace font")
)
Description: A compendium of 'geoms', 'coords', 'stats', scales and fonts for
'ggplot2', including splines, 1d and 2d densities, univariate average shifted
histograms, a new map coordinate system based on the 'PROJ.4'-library along
with a cartogram 'geom' that mimics the original functionality of
'geom_map', formatters for "bytes", a two-way bar 'geom' along with a
'stepribbon' 'geom', increased 'plotly' compatibility and the 'StateFace'
open source font 'ProPublica'. Further new functionality includes lollipop charts,
dumbbell charts, the ability to "encircle" points and coordinate-system-based
text annotations.
'geom_map', formatters for "bytes", a 'stepribbon' 'stat', increased 'plotly'
compatibility and the 'StateFace' open source font 'ProPublica'. Further new
functionality includes lollipop charts, dumbbell charts, the ability to "encircle"
points and coordinate-system-based text annotations.
License: AGPL + file LICENSE
LazyData: true
URL: https://github.com/hrbrmstr/ggalt

3
NAMESPACE

@ -15,7 +15,6 @@ export(GeomDumbbell)
export(GeomEncircle)
export(GeomLollipop)
export(GeomStateface)
export(GeomTwowayBar)
export(GeomXSpline2)
export(GeomXspline)
export(Kb)
@ -36,7 +35,6 @@ export(geom_dumbbell)
export(geom_encircle)
export(geom_lollipop)
export(geom_stateface)
export(geom_twoway_bar)
export(geom_xspline)
export(load_stateface)
export(show_stateface)
@ -82,6 +80,7 @@ importFrom(gtable,gtable_col)
importFrom(gtable,gtable_height)
importFrom(gtable,gtable_row)
importFrom(gtable,gtable_width)
importFrom(scales,comma)
importFrom(scales,expand_range)
importFrom(scales,rescale)
importFrom(tibble,as_tibble)

17
R/coord_proj.r

@ -18,6 +18,7 @@
#' \figure{coordproj01.png}{options: width=10cm}
#' }
#'
#' @note It is recommended that you use \code{geom_cartogram} with this coordinate system
#' @param proj projection definition. If left \code{NULL} will default to
#' a Robinson projection
#' @param inverse if \code{TRUE} inverse projection is performed (from a
@ -41,14 +42,14 @@
#' @export
#' @examples \dontrun{
#' # World in Winkel-Tripel
#' world <- map_data("world")
#' world <- world[world$region != "Antarctica",]
#'
#' gg <- ggplot()
#' gg <- gg + geom_cartogram(data=world, map=world,
#' aes(x=long, y=lat, map_id=region))
#' gg <- gg + coord_proj("+proj=wintri")
#' gg
# world <- map_data("world")
# world <- world[world$region != "Antarctica",]
#
# gg <- ggplot()
# gg <- gg + geom_cartogram(data=world, map=world,
# aes(x=long, y=lat, map_id=region))
# gg <- gg + coord_proj("+proj=wintri")
# gg
#'
#' # U.S.A. Albers-style
#' usa <- world[world$region == "USA",]

37
R/formatters.r

@ -18,6 +18,9 @@
#' @examples
#' byte_format()(sample(3000000000, 10))
#' bytes(sample(3000000000, 10))
#' Kb(sample(3000000000, 10))
#' Mb(sample(3000000000, 10))
#' Gb(sample(3000000000, 10))
byte_format <- function(symbol="auto", units="binary") {
function(x) bytes(x, symbol, units)
}
@ -58,25 +61,25 @@ bytes <- function(x, symbol="auto", units=c("binary", "si")) {
}
switch(symbol,
"b" =, "B" = paste(x, "bytes"),
"b" =, "B" = paste(x, "bytes"),
"Kb" =, "KB" = paste(round(x/(base^1), 1L), "Kb"),
"Mb" =, "MB" = paste(round(x/(base^2), 1L), "Mb"),
"Gb" =, "GB" = paste(round(x/(base^3), 1L), "Gb"),
"Tb" =, "TB" = paste(round(x/(base^4), 1L), "Tb"),
"Pb" =, "PB" = paste(round(x/(base^5), 1L), "Pb"),
"Eb" =, "EB" = paste(round(x/(base^6), 1L), "Eb"),
"Zb" =, "ZB" = paste(round(x/(base^7), 1L), "Zb"),
"Yb" =, "YB" = paste(round(x/(base^8), 1L), "Yb"),
"Kb" =, "KB" = paste(scales::comma(round(x/(base^1), 1L)), "Kb"),
"Mb" =, "MB" = paste(scales::comma(round(x/(base^2), 1L)), "Mb"),
"Gb" =, "GB" = paste(scales::comma(round(x/(base^3), 1L)), "Gb"),
"Tb" =, "TB" = paste(scales::comma(round(x/(base^4), 1L)), "Tb"),
"Pb" =, "PB" = paste(scales::comma(round(x/(base^5), 1L)), "Pb"),
"Eb" =, "EB" = paste(scales::comma(round(x/(base^6), 1L)), "Eb"),
"Zb" =, "ZB" = paste(scales::comma(round(x/(base^7), 1L)), "Zb"),
"Yb" =, "YB" = paste(scales::comma(round(x/(base^8), 1L)), "Yb"),
"KiB" = paste(round(x/(base^1), 1L), "KiB"),
"MiB" = paste(round(x/(base^2), 1L), "MiB"),
"GiB" = paste(round(x/(base^3), 1L), "GiB"),
"TiB" = paste(round(x/(base^4), 1L), "TiB"),
"PiB" = paste(round(x/(base^5), 1L), "PiB"),
"EiB" = paste(round(x/(base^6), 1L), "EiB"),
"ZiB" = paste(round(x/(base^7), 1L), "ZiB"),
"YiB" = paste(round(x/(base^8), 1L), "YiB")
"KiB" = paste(scales::comma(round(x/(base^1), 1L)), "KiB"),
"MiB" = paste(scales::comma(round(x/(base^2), 1L)), "MiB"),
"GiB" = paste(scales::comma(round(x/(base^3), 1L)), "GiB"),
"TiB" = paste(scales::comma(round(x/(base^4), 1L)), "TiB"),
"PiB" = paste(scales::comma(round(x/(base^5), 1L)), "PiB"),
"EiB" = paste(scales::comma(round(x/(base^6), 1L)), "EiB"),
"ZiB" = paste(scales::comma(round(x/(base^7), 1L)), "ZiB"),
"YiB" = paste(scales::comma(round(x/(base^8), 1L)), "YiB")
)
}

14
R/geom_dumbbell.R

@ -23,11 +23,17 @@
#' @inheritParams ggplot2::layer
#' @export
#' @examples
#' df <- data.frame(trt=LETTERS[1:5],
#' l=c(20, 40, 10, 30, 50),
#' r=c(70, 50, 30, 60, 80))
#' library(ggplot2)
#'
#' ggplot(df, aes(y=trt, x=l, xend=r)) + geom_dumbbell()
#' df <- data.frame(trt=LETTERS[1:5], l=c(20, 40, 10, 30, 50), r=c(70, 50, 30, 60, 80))
#'
#' ggplot(df, aes(y=trt, x=l, xend=r)) +
#' geom_dumbbell(size=3, color="#e3e2e1",
#' 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_minimal() +
#' theme(panel.grid.major.x=element_line(size=0.05))
geom_dumbbell <- function(mapping = NULL, data = NULL, ...,
colour_x = NULL, size_x = NULL,
colour_xend = NULL, size_xend = NULL,

188
R/geom_table.r

@ -1,94 +1,96 @@
# @rdname ggalt-ggproto
# @format NULL
# @usage NULL
# @export
GeomTable <- ggproto(
"GeomTable",
Geom,
required_aes = c("x", "y", "table"),
default_aes = aes(
widthx = 10,
widthy = 10,
rownames = NA
),
draw_key = draw_key_blank,
draw_panel = function(data, panel_scales, coord) {
if (nrow(data) != 1) {
stop(
sprintf(
"only one table per panel allowed, got %s (%s)",
nrow(data),
as.character(data)
),
call. = FALSE
)
}
wy = data$widthy / 2
wx = data$widthx / 2
corners <-
data.frame(x = c(data$x - wx, data$x + wx),
y = c(data$y - wy, data$y + wy))
d <- coord$transform(corners, panel_scales)
# gross hack, but I've found no other way to get a table/matrix/dataframe to this point :-(
table = read.csv(text = data$table, header = TRUE)
if (!is.na(data$rownames)) {
rownames(table) <-
unlist(strsplit(data$rownames, "|", fixed = TRUE))
}
x_rng <- range(d$x, na.rm = TRUE)
y_rng <- range(d$y, na.rm = TRUE)
vp <-
viewport(
x = mean(x_rng),
y = mean(y_rng),
width = diff(x_rng),
height = diff(y_rng),
just = c("center", "center")
)
grob <-
tableGrob(table, theme = ttheme_minimal())
# add a line across the header
grob <- gtable_add_grob(
grob,
grobs = segmentsGrob(y1 = unit(0, "npc"),
gp = gpar(lwd = 2.0)),
t = 1,
b = 1,
l = 1,
r = ncol(d) + 1
)
editGrob(grob, vp = vp, name = paste(grob$name, facet_id()))
}
)
facet_id <- local({
i <- 1
function() {
i <<- i + 1
i
}
})
# Add a table to a ggplot2 plot
# #' @rdname ggalt-ggproto
# #' @format NULL
# #' @usage NULL
# #' @export
# GeomTable <- ggproto(
# "GeomTable",
# Geom,
# required_aes = c("x", "y", "table"),
# default_aes = aes(
# widthx = 10,
# widthy = 10,
# rownames = NA
# ),
# draw_key = draw_key_blank,
#
# draw_panel = function(data, panel_scales, coord) {
# if (nrow(data) != 1) {
# stop(
# sprintf(
# "only one table per panel allowed, got %s (%s)",
# nrow(data),
# as.character(data)
# ),
# call. = FALSE
# )
# }
# wy = data$widthy / 2
# wx = data$widthx / 2
#
# corners <-
# data.frame(x = c(data$x - wx, data$x + wx),
# y = c(data$y - wy, data$y + wy))
# d <- coord$transform(corners, panel_scales)
#
# # gross hack, but I've found no other way to get a table/matrix/dataframe to this point :-(
# table = utils::read.csv(text = data$table, header = TRUE)
# if (!is.na(data$rownames)) {
# rownames(table) <-
# unlist(strsplit(data$rownames, "|", fixed = TRUE))
# }
#
# x_rng <- range(d$x, na.rm = TRUE)
# y_rng <- range(d$y, na.rm = TRUE)
#
# vp <-
# viewport(
# x = mean(x_rng),
# y = mean(y_rng),
# width = diff(x_rng),
# height = diff(y_rng),
# just = c("center", "center")
# )
#
# grob <-
# tableGrob(table, theme = ttheme_minimal())
# # add a line across the header
# grob <- gtable_add_grob(
# grob,
# grobs = segmentsGrob(y1 = unit(0, "npc"),
# gp = gpar(lwd = 2.0)),
# t = 1,
# b = 1,
# l = 1,
# r = ncol(d) + 1
# )
# editGrob(grob, vp = vp, name = paste(grob$name, facet_id()))
# }
# )
#
# facet_id <- local({
# i <- 1
# function() {
# i <<- i + 1
# i
# }
# })
#
# #' Add a table to a ggplot2 plot
# #'
# #' @export
# #' @author Jan Schulz
# geom_table <- function(mapping = NULL, data = NULL, stat = "identity",
# position = "identity", na.rm = FALSE,
# show.legend = NA, inherit.aes = TRUE, ...) {
# layer(
# geom = GeomTable,
# mapping = mapping,
# data = data,
# stat = stat,
# position = position,
# show.legend = show.legend,
# inherit.aes = inherit.aes,
# params = list(na.rm = na.rm, ...)
# )
# }
#
# @author Jan Schulz
geom_table <- function(mapping = NULL, data = NULL, stat = "identity",
position = "identity", na.rm = FALSE,
show.legend = NA, inherit.aes = TRUE, ...) {
layer(
geom = GeomTable,
mapping = mapping,
data = data,
stat = stat,
position = position,
show.legend = show.legend,
inherit.aes = inherit.aes,
params = list(na.rm = na.rm, ...)
)
}

151
R/geom_twoway_bar.r

@ -1,76 +1,77 @@
#' Two-way bar chart
#'
#' @inheritParams ggplot2::geom_bar
#' @export
geom_twoway_bar <- function(mapping = NULL, data = NULL,
stat = "identity",
width = NULL,
...,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
stat = stat,
geom = GeomTwowayBar,
position = "stack",
show.legend = show.legend,
inherit.aes = inherit.aes,
params = list(
width = width,
na.rm = na.rm,
...
)
)
}
#' @rdname ggalt-ggproto
#' @format NULL
#' @usage NULL
#' @export
GeomTwowayBar <- ggproto("GeomTwowayBar", GeomRect,
required_aes = c("x", "y"),
do_setup_data = function(data, params) {
data$width <- data$width %||%
params$width %||% (resolution(data$x, FALSE) * 0.9)
d_plus <- subset(data, y>=0, drop=FALSE)
d_minus <- subset(data, y<0, drop=FALSE)
d_plus <- transform(d_plus,
ymin = pmin(y, 0), ymax = pmax(y, 0),
xmin = x - width / 2, xmax = x + width / 2, width = NULL,
is_plus = TRUE
)
d_minus <- transform(d_minus,
ymin = pmin(y, 0), ymax = pmax(y, 0),
xmin = x - width / 2, xmax = x + width / 2, width = NULL,
y = abs(y),
is_plus = FALSE
)
cat("setup_data() after _________\n")
print(rbind(d_plus, d_minus))
rbind(d_plus, d_minus)
},
draw_panel = function(self, data, panel_scales, coord, width=NULL) {
cat("draw_panel() _________\n")
print(data)
# #' Two-way bar chart
# #'
# #' @inheritParams ggplot2::geom_bar
# #' @export
# geom_twoway_bar <- function(mapping = NULL, data = NULL,
# stat = "identity",
# width = NULL,
# ...,
# na.rm = FALSE,
# show.legend = NA,
# inherit.aes = TRUE) {
#
# layer(
# data = data,
# mapping = mapping,
# stat = stat,
# geom = GeomTwowayBar,
# position = "stack",
# show.legend = show.legend,
# inherit.aes = inherit.aes,
# params = list(
# width = width,
# na.rm = na.rm,
# ...
# )
# )
# }
#
# #' @rdname ggalt-ggproto
# #' @format NULL
# #' @usage NULL
# #' @export
# GeomTwowayBar <- ggproto("GeomTwowayBar", GeomRect,
# required_aes = c("x", "y"),
#
# do_setup_data = function(data, params) {
# data$width <- data$width %||%
# params$width %||% (resolution(data$x, FALSE) * 0.9)
#
# d_plus <- subset(data, y>=0, drop=FALSE)
# d_minus <- subset(data, y<0, drop=FALSE)
#
# d_plus <- transform(d_plus,
# ymin = pmin(y, 0), ymax = pmax(y, 0),
# xmin = x - width / 2, xmax = x + width / 2, width = NULL,
# is_plus = TRUE
# )
#
# d_minus <- transform(d_minus,
# ymin = pmin(y, 0), ymax = pmax(y, 0),
# xmin = x - width / 2, xmax = x + width / 2, width = NULL,
# y = abs(y),
# is_plus = FALSE
# )
#
# cat("setup_data() after _________\n")
# print(rbind(d_plus, d_minus))
#
# rbind(d_plus, d_minus)
#
# },
#
# draw_panel = function(self, data, panel_scales, coord, width=NULL) {
#
# cat("draw_panel() _________\n")
# print(data)
# #
# # d_plus <- subset(data, is_plus)
# # d_minus <- subset(data, !is_plus)
# # d_minus$y <- -d_minus$y
#
# gList(
# ggplot2::ggproto_parent(GeomBar, self)$draw_panel(data, panel_scales, coord)
# )
# }
# )
#
# d_plus <- subset(data, is_plus)
# d_minus <- subset(data, !is_plus)
# d_minus$y <- -d_minus$y
gList(
ggplot2::ggproto_parent(GeomBar, self)$draw_panel(data, panel_scales, coord)
)
}
)

2
R/ggalt-package.r

@ -8,7 +8,7 @@
#' @author Bob Rudis (@@hrbrmstr)
#' @import maps ggplot2 graphics grDevices KernSmooth proj4 ash MASS
#' @importFrom dplyr filter
#' @importFrom scales rescale expand_range
#' @importFrom scales rescale expand_range comma
#' @importFrom grid grobName grobTree unit.c grobHeight grobWidth viewport
#' grid.draw grobX grobY gTree gList textGrob gpar pointsGrob
#' segmentsGrob polygonGrob

4
R/zzz.r

@ -2,8 +2,8 @@
if (!interactive()) return()
packageStartupMessage(paste0("ggalt is under *active* development. ",
"See https://github.com/hrbrmstr/ggalt for changes"))
# packageStartupMessage(paste0("ggalt is under *active* development. ",
# "See https://github.com/hrbrmstr/ggalt for changes"))
}

10
README.Rmd

@ -23,12 +23,12 @@ The following functions are implemented:
- `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`)
- `geom_stateface`: Use ProPublica's StateFace font in ggplot2 plots- `stat_bkde` : Display a smooth density estimate (uses `KernSmooth::bkde`)
- `geom_bkde2d` : Contours from a 2d density estimate. (uses `KernSmooth::bkde2D`)
- `stat_bkde2d` : Contours from a 2d density estimate. (uses `KernSmooth::bkde2D`)
- `stat_ash` : Compute and display a univariate averaged shifted histogram (polynomial kernel) (uses `ash::ash1`/`ash::bin1`)
-- `geom_encircle`: Automatically enclose points in a polygon
`byte_format`: + helpers. e.g. turn `10000` into `10 Kb`
- `geom_encircle`: Automatically enclose points in a polygon
- `byte_format`: + helpers. e.g. turn `10000` into `10 Kb`
- `geom_lollipop()`: Dead easy lollipops (horizontal or vertical)
- `geom_dumbbell()` : Dead easy dumbbell plots
- `stat_stepribbon()` : Step ribbons
@ -310,10 +310,10 @@ 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,
health <- read.csv("https://rud.is/dl/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)
areas <- read.csv("https://rud.is/dl/zarea_trans.csv", stringsAsFactors=FALSE, header=TRUE)
health %>%
mutate(area_id=trunc(area_id)) %>%

11
README.md

@ -11,10 +11,13 @@ 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)
- `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`)
- `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_bkde2d` : Contours from a 2d density estimate. (uses `KernSmooth::bkde2D`)
- `stat_bkde2d` : Contours from a 2d density estimate. (uses `KernSmooth::bkde2D`)
- `stat_ash` : Compute and display a univariate averaged shifted histogram (polynomial kernel) (uses `ash::ash1`/`ash::bin1`) -- `geom_encircle`: Automatically enclose points in a polygon `byte_format`: + helpers. e.g. turn `10000` into `10 Kb`
- `stat_ash` : Compute and display a univariate averaged shifted histogram (polynomial kernel) (uses `ash::ash1`/`ash::bin1`)
- `geom_encircle`: Automatically enclose points in a polygon
- `byte_format`: + helpers. e.g. turn `10000` into `10 Kb`
- `geom_lollipop()`: Dead easy lollipops (horizontal or vertical)
- `geom_dumbbell()` : Dead easy dumbbell plots
- `stat_stepribbon()` : Step ribbons
@ -435,10 +438,10 @@ 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,
health <- read.csv("https://rud.is/dl/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)
areas <- read.csv("https://rud.is/dl/zarea_trans.csv", stringsAsFactors=FALSE, header=TRUE)
health %>%
mutate(area_id=trunc(area_id)) %>%

BIN
README_figs/README-dumbbell2-1.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 35 KiB

17
cran-comments.md

@ -0,0 +1,17 @@
## Test environments
* local OS X install, R 3.3.2
* ubuntu 14.04 (on travis-ci), old, current, devel
* win-builder (devel and release)
## R CMD check results
0 errors | 0 warnings | 0 notes
## Reverse dependencies
This is a new release, so there are no reverse dependencies.
---
* Fixes errors in the CRAN checks after the ggplot2 2.2.1 release
* Adds new functionality (new geoms and stats and scales)

3
man/byte_format.Rd

@ -42,6 +42,9 @@ Bytes formatter: convert to byte measurement and display symbol.
\examples{
byte_format()(sample(3000000000, 10))
bytes(sample(3000000000, 10))
Kb(sample(3000000000, 10))
Mb(sample(3000000000, 10))
Gb(sample(3000000000, 10))
}
\references{
Units of Information (Wikipedia) :

10
man/coord_proj.Rd

@ -50,6 +50,8 @@ A sample of the output from \code{coord_proj()} using the Winkel-Tripel projecti
}
}
\note{
It is recommended that you use \code{geom_cartogram} with this coordinate system
When \code{inverse} is \code{FALSE} \code{coord_proj} makes a fairly
large assumption that the coordinates being transformed are within
-180:180 (longitude) and -90:90 (latitude). As such, it truncates
@ -59,14 +61,6 @@ When \code{inverse} is \code{FALSE} \code{coord_proj} makes a fairly
\examples{
\dontrun{
# World in Winkel-Tripel
world <- map_data("world")
world <- world[world$region != "Antarctica",]
gg <- ggplot()
gg <- gg + geom_cartogram(data=world, map=world,
aes(x=long, y=lat, map_id=region))
gg <- gg + coord_proj("+proj=wintri")
gg
# U.S.A. Albers-style
usa <- world[world$region == "USA",]

14
man/geom_dumbbell.Rd

@ -71,9 +71,15 @@ alternative to the clustered bar chart or slope graph.
}
\examples{
df <- data.frame(trt=LETTERS[1:5],
l=c(20, 40, 10, 30, 50),
r=c(70, 50, 30, 60, 80))
library(ggplot2)
ggplot(df, aes(y=trt, x=l, xend=r)) + geom_dumbbell()
df <- data.frame(trt=LETTERS[1:5], l=c(20, 40, 10, 30, 50), r=c(70, 50, 30, 60, 80))
ggplot(df, aes(y=trt, x=l, xend=r)) +
geom_dumbbell(size=3, color="#e3e2e1",
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_minimal() +
theme(panel.grid.major.x=element_line(size=0.05))
}

55
man/geom_twoway_bar.Rd

@ -1,55 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/geom_twoway_bar.r
\name{geom_twoway_bar}
\alias{geom_twoway_bar}
\title{Two-way bar chart}
\usage{
geom_twoway_bar(mapping = NULL, data = NULL, stat = "identity",
width = 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{stat}{Override the default connection between \code{geom_bar} and
\code{stat_count}.}
\item{width}{Bar width. By default, set to 90\% of the resolution of the 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{na.rm}{If \code{FALSE}, the default, missing values are removed with
a warning. If \code{TRUE}, missing values are silently removed.}
\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{
Two-way bar chart
}

4
man/ggalt-ggproto.Rd

@ -1,8 +1,7 @@
% 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_dumbbell.R, R/geom_encircle.r, R/geom_lollipop.r,
% R/geom_twoway_bar.r, R/geom_xspline.r, R/geom_xspline2.r,
% R/stat-stepribbon.r, R/stateface.r
% R/geom_xspline.r, R/geom_xspline2.r, R/stat-stepribbon.r, R/stateface.r
\docType{data}
\name{CoordProj}
\alias{CoordProj}
@ -14,7 +13,6 @@
\alias{GeomDumbbell}
\alias{GeomEncircle}
\alias{GeomLollipop}
\alias{GeomTwowayBar}
\alias{GeomXspline}
\alias{StatXspline}
\alias{GeomXSpline2}

265
vignettes/ggalt_examples.Rmd

@ -0,0 +1,265 @@
---
title: "ggalt examples"
author: "Bob Rudis"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{ggalt examples}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r include=FALSE}
knitr::opts_chunk$set(collapse=TRUE, comment="##", fig.retina=1, fig.height=6, fig.width=8)
```
```{r}
library(ggplot2)
library(gridExtra)
library(ggalt)
library(scales)
# current verison
packageVersion("ggalt")
set.seed(1492)
dat <- data.frame(x=c(1:10, 1:10, 1:10),
y=c(sample(15:30, 10), 2*sample(15:30, 10), 3*sample(15:30, 10)),
group=factor(c(rep(1, 10), rep(2, 10), rep(3, 10)))
)
```
### Splines!
```{r splines}
ggplot(dat, aes(x, y, group=group, color=group)) +
geom_point() +
geom_line()
ggplot(dat, aes(x, y, group=group, color=factor(group))) +
geom_point() +
geom_line() +
geom_smooth(se=FALSE, linetype="dashed", size=0.5)
ggplot(dat, aes(x, y, group=group, color=factor(group))) +
geom_point(color="black") +
geom_smooth(se=FALSE, linetype="dashed", size=0.5) +
geom_xspline(size=0.5)
ggplot(dat, aes(x, y, group=group, color=factor(group))) +
geom_point(color="black") +
geom_smooth(se=FALSE, linetype="dashed", size=0.5) +
geom_xspline(spline_shape=-0.4, size=0.5)
ggplot(dat, aes(x, y, group=group, color=factor(group))) +
geom_point(color="black") +
geom_smooth(se=FALSE, linetype="dashed", size=0.5) +
geom_xspline(spline_shape=0.4, size=0.5)
ggplot(dat, aes(x, y, group=group, color=factor(group))) +
geom_point(color="black") +
geom_smooth(se=FALSE, linetype="dashed", size=0.5) +
geom_xspline(spline_shape=1, size=0.5)
ggplot(dat, aes(x, y, group=group, color=factor(group))) +
geom_point(color="black") +
geom_smooth(se=FALSE, linetype="dashed", size=0.5) +
geom_xspline(spline_shape=0, size=0.5)
ggplot(dat, aes(x, y, group=group, color=factor(group))) +
geom_point(color="black") +
geom_smooth(se=FALSE, linetype="dashed", size=0.5) +
geom_xspline(spline_shape=-1, size=0.5)
```
#### Alternate (better) density plots
```{r bkde_ash}
# bkde
data(geyser, package="MASS")
ggplot(geyser, aes(x=duration)) +
stat_bkde(alpha=1/2)
ggplot(geyser, aes(x=duration)) +
geom_bkde(alpha=1/2)
ggplot(geyser, aes(x=duration)) +
stat_bkde(bandwidth=0.25)
ggplot(geyser, aes(x=duration)) +
geom_bkde(bandwidth=0.25)
set.seed(1492)
dat <- data.frame(cond = factor(rep(c("A","B"), each=200)),
rating = c(rnorm(200),rnorm(200, mean=.8)))
ggplot(dat, aes(x=rating, color=cond)) + geom_bkde(fill="#00000000")
ggplot(dat, aes(x=rating, fill=cond)) + geom_bkde(alpha=0.3)
# ash
set.seed(1492)
dat <- data.frame(x=rnorm(100))
grid.arrange(ggplot(dat, aes(x)) + stat_ash(),
ggplot(dat, aes(x)) + stat_bkde(),
ggplot(dat, aes(x)) + stat_density(),
nrow=3)
cols <- RColorBrewer::brewer.pal(3, "Dark2")
ggplot(dat, aes(x)) +
stat_ash(alpha=1/3, fill=cols[3]) +
stat_bkde(alpha=1/3, fill=cols[2]) +
stat_density(alpha=1/3, fill=cols[1]) +
geom_rug() +
labs(x=NULL, y="density/estimate") +
scale_x_continuous(expand=c(0,0)) +
theme_bw() +
theme(panel.grid=element_blank()) +
theme(panel.border=element_blank())
```
### Alternate 2D density plots
```{r bkde2d}
m <- ggplot(faithful, aes(x = eruptions, y = waiting)) +
geom_point() +
xlim(0.5, 6) +
ylim(40, 110)
m + geom_bkde2d(bandwidth=c(0.5, 4))
m + stat_bkde2d(bandwidth=c(0.5, 4), aes(fill = ..level..), geom = "polygon")
```
### ProPublica StateFace
```{r stateface}
# Run show_stateface() to see the location of the TTF StateFace font
# You need to install it for it to work
set.seed(1492)
dat <- data.frame(state=state.abb,
x=sample(100, 50),
y=sample(100, 50),
col=sample(c("#b2182b", "#2166ac"), 50, replace=TRUE),
sz=sample(6:15, 50, replace=TRUE),
stringsAsFactors=FALSE)
gg <- ggplot(dat, aes(x=x, y=y))
gg <- gg + geom_stateface(aes(label=state, color=col, size=sz))
gg <- gg + scale_color_identity()
gg <- gg + scale_size_identity()
gg
```
### Encircling points automagically
```{r encircle}
d <- data.frame(x=c(1,1,2),y=c(1,2,2)*100)
gg <- ggplot(d,aes(x,y))
gg <- gg + scale_x_continuous(expand=c(0.5,1))
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.1, colour="red") + geom_point()
gg + geom_encircle(s_shape=0.5, expand=0.1, colour="purple") + geom_point()
gg + geom_encircle(data=subset(d, x==1), colour="blue", spread=0.02) +
geom_point()
gg +geom_encircle(data=subset(d, x==2), colour="cyan", spread=0.04) +
geom_point()
gg <- ggplot(mpg, aes(displ, hwy))
gg + geom_encircle(data=subset(mpg, hwy>40)) + geom_point()
ss <- subset(mpg,hwy>31 & displ<2)
gg + geom_encircle(data=ss, colour="blue", s_shape=0.9, expand=0.07) +
geom_point() + geom_point(data=ss, colour="blue")
```
### Step ribbons
```{r stepribbon}
x <- 1:10
df <- data.frame(x=x, y=x+10, ymin=x+7, ymax=x+12)
gg <- ggplot(df, aes(x, y))
gg <- gg + geom_ribbon(aes(ymin=ymin, ymax=ymax),
stat="stepribbon", fill="#b2b2b2")
gg <- gg + geom_step(color="#2b2b2b")
gg
gg <- ggplot(df, aes(x, y))
gg <- gg + geom_ribbon(aes(ymin=ymin, ymax=ymax),
stat="stepribbon", fill="#b2b2b2",
direction="vh")
gg <- gg + geom_step(color="#2b2b2b")
gg
```
### Lollipop charts
```{r lollipop}
df <- read.csv(text="category,pct
Other,0.09
South Asian/South Asian Americans,0.12
Interngenerational/Generational,0.21
S Asian/Asian Americans,0.25
Muslim Observance,0.29
Africa/Pan Africa/African Americans,0.34
Gender Equity,0.34
Disability Advocacy,0.49
European/European Americans,0.52
Veteran,0.54
Pacific Islander/Pacific Islander Americans,0.59
Non-Traditional Students,0.61
Religious Equity,0.64
Caribbean/Caribbean Americans,0.67
Latino/Latina,0.69
Middle Eastern Heritages and Traditions,0.73
Trans-racial Adoptee/Parent,0.76
LBGTQ/Ally,0.79
Mixed Race,0.80
Jewish Heritage/Observance,0.85
International Students,0.87", stringsAsFactors=FALSE, sep=",", header=TRUE)
gg <- ggplot(df, aes(y=reorder(category, pct), x=pct))
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,
title="SUNY Cortland Multicultural Alumni survey results",
subtitle="Ranked by race, ethnicity, home land and orientation\namong the top areas of concern",
caption="Data from http://stephanieevergreen.com/lollipop/")
gg <- gg + theme_minimal()
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=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)))
gg <- gg + theme(plot.caption=element_text(size=8, margin=margin(t=10)))
gg
```
### Dumbbell charts
```{r dumbbell2, message=FALSE, fig.width=7, fig.height=2.5}
df <- data.frame(trt=LETTERS[1:5], l=c(20, 40, 10, 30, 50), r=c(70, 50, 30, 60, 80))
ggplot(df, aes(y=trt, x=l, xend=r)) +
geom_dumbbell(size=3, color="#e3e2e1",
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_minimal() +
theme(panel.grid.major.x=element_line(size=0.05)) +
theme(panel.grid.major.y=element_blank())
```
Loading…
Cancel
Save