Browse Source

pictogram

pull/65/head
boB Rudis 5 years ago
parent
commit
b26e533afe
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 3
      DESCRIPTION
  2. 9
      NAMESPACE
  3. 35
      R/fontawesome.R
  4. 352
      R/geom-pictogram.R
  5. 305
      R/geom-waffle.R
  6. 143
      R/stat-pictogram.R
  7. 286
      R/stat-waffle.R
  8. 355
      R/sw2.R
  9. 3
      R/utils.r
  10. 3
      R/waffle-package.R
  11. 80
      README.Rmd
  12. 96
      README.md
  13. 14
      README_cache/gfm/__packages
  14. BIN
      README_cache/gfm/f5_4ad4736778ddf27b4931aadaacaac8ac.RData
  15. 0
      README_cache/gfm/f5_4ad4736778ddf27b4931aadaacaac8ac.rdb
  16. BIN
      README_cache/gfm/f5_4ad4736778ddf27b4931aadaacaac8ac.rdx
  17. BIN
      README_cache/gfm/f8_64fe7a35a243319e74cbbdad7227be28.RData
  18. BIN
      README_cache/gfm/f8_64fe7a35a243319e74cbbdad7227be28.rdb
  19. BIN
      README_cache/gfm/f8_64fe7a35a243319e74cbbdad7227be28.rdx
  20. BIN
      README_cache/gfm/fct_fa2af6d9218db86d6d178d3bbd2466a4.RData
  21. 0
      README_cache/gfm/fct_fa2af6d9218db86d6d178d3bbd2466a4.rdb
  22. BIN
      README_cache/gfm/fct_fa2af6d9218db86d6d178d3bbd2466a4.rdx
  23. BIN
      README_cache/gfm/fig0_a8d5a1e257eb143faece4bed088744ca.RData
  24. BIN
      README_cache/gfm/fig0_a8d5a1e257eb143faece4bed088744ca.rdb
  25. BIN
      README_cache/gfm/fig0_a8d5a1e257eb143faece4bed088744ca.rdx
  26. BIN
      README_cache/gfm/fig1_203fd0f3bc8c6069277b2a93c9fafa60.RData
  27. BIN
      README_cache/gfm/fig1_203fd0f3bc8c6069277b2a93c9fafa60.rdb
  28. BIN
      README_cache/gfm/fig1_203fd0f3bc8c6069277b2a93c9fafa60.rdx
  29. BIN
      README_cache/gfm/fig2_76e8ea5d53b53979b80bafc55421117f.RData
  30. 0
      README_cache/gfm/fig2_76e8ea5d53b53979b80bafc55421117f.rdb
  31. BIN
      README_cache/gfm/fig2_76e8ea5d53b53979b80bafc55421117f.rdx
  32. BIN
      README_cache/gfm/fig3_a2a7a52b2ec33fcf5202e1f938eaab82.RData
  33. 0
      README_cache/gfm/fig3_a2a7a52b2ec33fcf5202e1f938eaab82.rdb
  34. BIN
      README_cache/gfm/fig3_a2a7a52b2ec33fcf5202e1f938eaab82.rdx
  35. BIN
      README_cache/gfm/fig4_ac3e92ba84f83b56b7881968998decfa.RData
  36. 0
      README_cache/gfm/fig4_ac3e92ba84f83b56b7881968998decfa.rdb
  37. BIN
      README_cache/gfm/fig4_ac3e92ba84f83b56b7881968998decfa.rdx
  38. BIN
      README_cache/gfm/fig4a_6cd3b719ae840625775a57ab9b9c2ae5.RData
  39. 0
      README_cache/gfm/fig4a_6cd3b719ae840625775a57ab9b9c2ae5.rdb
  40. BIN
      README_cache/gfm/fig4a_6cd3b719ae840625775a57ab9b9c2ae5.rdx
  41. BIN
      README_cache/gfm/geoms_908ed3f0fa75ec43dbfcee122a632d10.RData
  42. BIN
      README_cache/gfm/geoms_908ed3f0fa75ec43dbfcee122a632d10.rdb
  43. BIN
      README_cache/gfm/geoms_908ed3f0fa75ec43dbfcee122a632d10.rdx
  44. BIN
      README_cache/gfm/ingredients_03d07729b8c87f59927b3d580f1db2f9.RData
  45. 0
      README_cache/gfm/ingredients_03d07729b8c87f59927b3d580f1db2f9.rdb
  46. BIN
      README_cache/gfm/ingredients_03d07729b8c87f59927b3d580f1db2f9.rdx
  47. BIN
      README_cache/gfm/medkit0_7c3701449a0fd4fc396c95ab06356811.RData
  48. 0
      README_cache/gfm/medkit0_7c3701449a0fd4fc396c95ab06356811.rdb
  49. BIN
      README_cache/gfm/medkit0_7c3701449a0fd4fc396c95ab06356811.rdx
  50. BIN
      README_cache/gfm/medkit_660b2606a5fa68d594bdd6998a182c35.RData
  51. 0
      README_cache/gfm/medkit_660b2606a5fa68d594bdd6998a182c35.rdb
  52. BIN
      README_cache/gfm/medkit_660b2606a5fa68d594bdd6998a182c35.rdx
  53. BIN
      README_cache/gfm/no_fct_e57ef189ba393cd466eb8345744894b7.RData
  54. 0
      README_cache/gfm/no_fct_e57ef189ba393cd466eb8345744894b7.rdb
  55. BIN
      README_cache/gfm/no_fct_e57ef189ba393cd466eb8345744894b7.rdx
  56. BIN
      README_cache/gfm/nstall-ex_47a60990e2d319f8433b2210a6890028.RData
  57. 0
      README_cache/gfm/nstall-ex_47a60990e2d319f8433b2210a6890028.rdb
  58. BIN
      README_cache/gfm/nstall-ex_47a60990e2d319f8433b2210a6890028.rdx
  59. BIN
      README_cache/gfm/s2_66cee9d85dc6a99ef20315ebeab21b5b.RData
  60. 0
      README_cache/gfm/s2_66cee9d85dc6a99ef20315ebeab21b5b.rdb
  61. BIN
      README_cache/gfm/s2_66cee9d85dc6a99ef20315ebeab21b5b.rdx
  62. BIN
      README_cache/gfm/s4_f7b6c188da6eb517c5c45416691b5e7f.RData
  63. BIN
      README_cache/gfm/s4_f7b6c188da6eb517c5c45416691b5e7f.rdb
  64. BIN
      README_cache/gfm/s4_f7b6c188da6eb517c5c45416691b5e7f.rdx
  65. BIN
      README_cache/gfm/s5_f40630030d69783eead525c32f428060.RData
  66. BIN
      README_cache/gfm/s5_f40630030d69783eead525c32f428060.rdb
  67. BIN
      README_cache/gfm/s5_f40630030d69783eead525c32f428060.rdx
  68. BIN
      README_cache/gfm/s6_ff0c8f3ad2fcc652170b8bf9592357d3.RData
  69. BIN
      README_cache/gfm/s6_ff0c8f3ad2fcc652170b8bf9592357d3.rdb
  70. BIN
      README_cache/gfm/s6_ff0c8f3ad2fcc652170b8bf9592357d3.rdx
  71. BIN
      README_cache/gfm/t1_f04db1ac25ff0686d88ab58a3f2d4d70.RData
  72. 0
      README_cache/gfm/t1_f04db1ac25ff0686d88ab58a3f2d4d70.rdb
  73. BIN
      README_cache/gfm/t1_f04db1ac25ff0686d88ab58a3f2d4d70.rdx
  74. BIN
      README_cache/gfm/t2_733bbc8dbd0b116c20bf35aeeb87d511.RData
  75. 0
      README_cache/gfm/t2_733bbc8dbd0b116c20bf35aeeb87d511.rdb
  76. BIN
      README_cache/gfm/t2_733bbc8dbd0b116c20bf35aeeb87d511.rdx
  77. BIN
      README_cache/gfm/t5_00c0c60f098627065befce9733d2db8a.RData
  78. 0
      README_cache/gfm/t5_00c0c60f098627065befce9733d2db8a.rdb
  79. BIN
      README_cache/gfm/t5_00c0c60f098627065befce9733d2db8a.rdx
  80. BIN
      README_cache/gfm/unnamed-chunk-2_f358e3ab09a199cd320485fc64c5927a.RData
  81. BIN
      README_cache/gfm/unnamed-chunk-2_f358e3ab09a199cd320485fc64c5927a.rdb
  82. BIN
      README_cache/gfm/unnamed-chunk-2_f358e3ab09a199cd320485fc64c5927a.rdx
  83. BIN
      README_cache/gfm/unnamed-chunk-3_9f255a7595eed3b772236e145ed48614.RData
  84. 0
      README_cache/gfm/unnamed-chunk-3_9f255a7595eed3b772236e145ed48614.rdb
  85. BIN
      README_cache/gfm/unnamed-chunk-3_9f255a7595eed3b772236e145ed48614.rdx
  86. BIN
      README_cache/gfm/waffle-bars_885120d387eb4c3e265330249432d960.RData
  87. BIN
      README_cache/gfm/waffle-bars_885120d387eb4c3e265330249432d960.rdb
  88. BIN
      README_cache/gfm/waffle-bars_885120d387eb4c3e265330249432d960.rdx
  89. BIN
      README_files/figure-gfm/unnamed-chunk-2-1.png
  90. BIN
      README_files/figure-gfm/unnamed-chunk-2-2.png
  91. BIN
      README_files/figure-gfm/unnamed-chunk-2-3.png
  92. BIN
      inst/fonts/fa-regular-400.ttf
  93. 16
      man/geom_waffle.Rd
  94. 2
      waffle.Rproj

3
DESCRIPTION

@ -46,6 +46,7 @@ Imports:
stringr,
stats,
htmlwidgets,
DT
DT,
rlang
RoxygenNote: 6.1.1
VignetteBuilder: knitr

9
NAMESPACE

@ -1,12 +1,15 @@
# Generated by roxygen2: do not edit by hand
export(GeomPictogram)
export(GeomWaffle)
export(StatWaffle)
export(fa_grep)
export(fa_list)
export(geom_pictogram)
export(geom_waffle)
export(install_fa_fonts)
export(iron)
export(scale_label_pictogram)
export(stat_waffle)
export(theme_enhance_waffle)
export(waffle)
@ -21,6 +24,7 @@ importFrom(extrafont,font_import)
importFrom(extrafont,ttf_import)
importFrom(ggplot2,aes)
importFrom(ggplot2,coord_equal)
importFrom(ggplot2,discrete_scale)
importFrom(ggplot2,element_blank)
importFrom(ggplot2,element_rect)
importFrom(ggplot2,element_text)
@ -40,11 +44,16 @@ importFrom(ggplot2,scale_y_continuous)
importFrom(ggplot2,theme)
importFrom(ggplot2,theme_bw)
importFrom(grid,arrow)
importFrom(grid,gpar)
importFrom(grid,grid.draw)
importFrom(grid,grid.newpage)
importFrom(grid,grobTree)
importFrom(grid,roundrectGrob)
importFrom(grid,textGrob)
importFrom(grid,unit)
importFrom(grid,unit.c)
importFrom(grid,unit.pmax)
importFrom(grid,unit.pmin)
importFrom(gtable,is.gtable)
importFrom(rlang,is_missing)
importFrom(stats,setNames)

35
R/fontawesome.R

@ -2,39 +2,8 @@
# This variation updates it from the latests css from github
.fa_unicode_init <- function() {
# fa_lib <- readLines(system.file("css", "fontawesome.css", package="waffle"))
# fa_json <- jsonlite::fromJSON(system.file("json", "icons.json", package="waffle"))
#
# data.frame(
# name = names(fa_json),
# type = vapply(fa_json, function(.x, wat) .x[[wat]][[1]],
# character(1), "free", USE.NAMES = FALSE),
# unicode = vapply(fa_json, function(.x, wat) .x[[wat]][[1]],
# character(1), "unicode", USE.NAMES = FALSE),
# stringsAsFactors = FALSE
# ) -> fa_df
#
# vapply(
# seq_along(fa_df[["name"]]),
# function(.i) {
# # name <- fa_df[.i, "name"]
# type <- fa_df[.i, "type"]
# fa_json[[.i]][["svg"]][[type]][["raw"]]
# },
# character(1), USE.NAMES = FALSE
# ) -> fa_df[["glyph"]]
#
# fa_df[["unicode"]] <- as.character(
# parse(text = shQuote(stringr::str_c('\\u', fa_df[["unicode"]])))
# )
#
# fa_df <- fa_df[complete.cases(fa_df),]
#
# return(fa_df)
#
return(readRDS(system.file("extdat/fadf.rds", package = "waffle")))
xdf <- readRDS(system.file("extdat/fadf.rds", package = "waffle"))
xdf[xdf[["type"]] != "regular", ]
}

352
R/geom-pictogram.R

@ -1,234 +1,118 @@
# #' @export
# draw_key_pictogram <- function(data, params, size) {
#
# # message("Called draw_key_pictogram()")
#
# # print(str(data, 1))
# # print(str(params, 1))
# # print(str(size, 1))
#
# # return(draw_key_text(data, params, size))
#
# data[["label"]] <- .fa_unicode[.fa_unicode[["name"]] %in% data[["fa_glyph"]], "unicode"]
# fat <- .fa_unicode[.fa_unicode[["name"]] %in% data[["fa_glyph"]], "type"]
# ftrans <- c(solid = "FontAwesome5Free-Solid", brands = "FontAwesome5Brands-Regular")
# data[["family"]] <- ftrans[fat]
# data[["size"]] <- data[["size"]] * 2
#
# grid::textGrob(
# data$label, 0.5, 0.25,
# rot = data$angle %||% 0,
# gp = grid::gpar(
# col = alpha(data$colour %||% data$fill %||% "black", data$alpha),
# fontfamily = data$family %||% "",
# fontface = data$fontface %||% 1,
# fontsize = (data$size %||% 3.88) * .pt
# )
# )
# }
# #' Isotype pictogram "waffle" charts
# #'
# #' There are two special/critical `aes()` mappings:
# #' - `colour` (so the geom knows which column to map the country names/abbrevs to)
# #' - `values` (which column you're mapping the filling for the squares with)
# #'
# #' @md
# #' @param mapping Set of aesthetic mappings created by `aes()` or
# #' `aes_()`. If specified and `inherit.aes = TRUE` (the
# #' default), it is combined with the default mapping at the top level of the
# #' plot. You must supply `mapping` if there is no plot mapping.
# #' @param n_rows how many rows should there be in the waffle chart? default is 10
# #' @param flip If `TRUE`, flip x and y coords. n_rows then becomes n_cols.
# #' Useful to achieve waffle column chart effect. Defaults is `FALSE`.
# #' @param make_proportional compute proportions from the raw values? (i.e. each
# #' value `n` will be replaced with `n`/`sum(n)`); default is `FALSE`.
# #' @param data The data to be displayed in this layer. There are three
# #' options:
# #'
# #' If `NULL`, the default, the data is inherited from the plot
# #' data as specified in the call to `ggplot()`.
# #'
# #' A `data.frame`, or other object, will override the plot
# #' data. All objects will be fortified to produce a data frame. See
# #' `fortify()` for which variables will be created.
# #'
# #' A `function` will be called with a single argument,
# #' the plot data. The return value must be a `data.frame.`, and
# #' will be used as the layer data.
# #' @param na.rm If `FALSE`, the default, missing values are removed with
# #' a warning. If `TRUE`, missing values are silently removed.
# #' @param show.legend logical. Should this layer be included in the legends?
# #' `NA`, the default, includes if any aesthetics are mapped.
# #' `FALSE` never includes, and `TRUE` always includes.
# #' It can also be a named logical vector to finely select the aesthetics to
# #' display.
# #' @param inherit.aes If `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. `borders()`.
# #' @param ... other arguments passed on to `layer()`. These are
# #' often aesthetics, used to set an aesthetic to a fixed value, like
# #' `color = "red"` or `size = 3`. They may also be parameters
# #' to the paired geom/stat.
# #' @export
# #' @examples
# #' data.frame(
# #' parts = factor(rep(month.abb[1:3], 3), levels=month.abb[1:3]),
# #' values = c(10, 20, 30, 6, 14, 40, 30, 20, 10),
# #' fct = c(rep("Thing 1", 3), rep("Thing 2", 3), rep("Thing 3", 3))
# #' ) -> xdf
# #'
# #' ggplot(xdf, aes(fill = parts, values = values)) +
# #' geom_pictogram() +
# #' facet_wrap(~fct) +
# #' coord_equal()
# geom_pictogram <- function(
# mapping = NULL, data = NULL,
# n_rows = 10, flip = FALSE, make_proportional = FALSE,
# na.rm = TRUE, show.legend = NA, inherit.aes = TRUE, ...) {
#
# # message("Called geom_pictogram()")
#
# ggplot2::layer(
# data = data,
# mapping = mapping,
# stat = "pictogram",
# geom = GeomPictogram,
# position = "identity",
# show.legend = show.legend,
# inherit.aes = inherit.aes,
# check.aes = FALSE,
# params = list(
# na.rm = na.rm,
# n_rows = n_rows,
# flip = flip,
# make_proportional = make_proportional,
# use = "colour",
# ...
# )
# )
#
# }
#
# #' @rdname geom_pictogram
# #' @export
# GeomPictogram <- ggplot2::ggproto(
# `_class` = "GeomPictogram",
# `_inherit` = ggplot2::Geom,
#
# default_aes = ggplot2::aes(
# fa_glyph = "circle", fa_type = "solid",
# fill = NA, colour = "#b2b2b2", alpha = NA,
# size = 2, linetype = 1, width = NA, height = NA
# ),
#
# required_aes = c("x", "y", "values", "fa_glyph", "fa_type"),
#
# extra_params = c("na.rm", "width", "height", "flip", "use"),
#
# setup_data = function(data, params) {
#
# # message("Called GeomPictogram::setup_data()")
# # print(str(data, 1))
#
# waf.dat <- data
#
# # swap x and y values if flip is TRUE
# if (params$flip) {
# waf.dat$x_temp <- waf.dat$x
# waf.dat$x <- waf.dat$y
# waf.dat$y <- waf.dat$x_temp
# waf.dat$x_temp <- NULL
# }
#
# # reduce all values by 0.5
# # this allows for axis ticks to align _between_ square rows/cols
# # rather than in the middle of a row/col
# waf.dat$x <- waf.dat$x - 0.5
# waf.dat$y <- waf.dat$y - 0.5
#
# waf.dat$width <- waf.dat$width %||% params$width %||% ggplot2::resolution(waf.dat$x, FALSE)
# waf.dat$height <- waf.dat$height %||% params$height %||% ggplot2::resolution(waf.dat$y, FALSE)
#
# transform(
# waf.dat,
# xmin = x - width / 2,
# xmax = x + width / 2,
# width = NULL,
# ymin = y - height / 2,
# ymax = y + height / 2,
# height = NULL
# ) -> xdat
#
# # print(str(xdat, 1))
#
# xdat
#
# },
#
# draw_group = function(self, data, panel_params, coord,
# n_rows = 10, make_proportional = FALSE) {
#
# # message("Called GeomPictogram::draw_group()")
#
# # message("Called GEOM draw_group()")
#
# tile_data <- data
# # tile_data$size <- border_size
# # tile_data$colour <- border_col
#
# coord <- ggplot2::coord_equal()
#
# # gg <- gg + geom_tile(
# # color = "#00000000", fill = "#00000000", size = size,
# # alpha = 0, show.legend = FALSE
# # )
#
# gtdat <- tile_data
# gtdat[["colour"]] <- "#00000000"
# gtdat[["color"]] <- "#00000000"
# gtdat[["fill"]] <- "#00000000"
#
# g_pgdat <<- tile_data
#
# self$default_aes[["fa_glyph"]] <- tile_data[["fa_glyph"]][[1]]
#
# pgdat <- tile_data
# pgdat[["label"]] <- .fa_unicode[.fa_unicode[["name"]] %in% pgdat[["fa_glyph"]], "unicode"]
# fat <- .fa_unicode[.fa_unicode[["name"]] %in% pgdat[["fa_glyph"]], "type"]
# ftrans <- c(solid = "FontAwesome5Free-Solid", brands = "FontAwesome5Brands-Regular")
# pgdat[["family"]] <- ftrans[fat]
# pgdat[["size"]] <- pgdat[["size"]] * 2
# pgdat[["angle"]] = 0
# pgdat[["hjust"]] <- 0.5
# pgdat[["vjust"]] <- 0.5
# pgdat[["fontface"]] <- 1
# pgdat[["lineheight"]] <- 1
#
# # print(str(pgdat, 1))
#
# # gg <- gg + geom_text(
# # aes(color = value, label = fontlab),
# # family = glyph_font_family,
# # size = glyph_size,
# # show.legend = FALSE
# # )
#
# grid::gList(
# # GeomTile$draw_panel(gtdat, panel_params, coord),
# GeomText$draw_panel(pgdat, panel_params, coord)
# ) -> grobs
#
# ggname("geom_pictogram", grid::grobTree(children = grobs))
#
# },
#
# aesthetics = function(self) {
# # message("Called GeomPictogram::aesthetics()")
# c(union(self$required_aes, names(self$default_aes)), self$optional_aes, "group")
# },
#
# draw_key = draw_key_pictogram
#
# )
#
picto_scale <- function(aesthetic, values = NULL, ...) {
values <- if (is_missing(values)) "circle" else force(values)
pal <- function(n) {
vapply(
if (n > length(values)) rep(values[[1]], n) else values,
function(.x) .fa_unicode[.fa_unicode[["name"]] == .x, "unicode"],
character(1),
USE.NAMES = FALSE
)
}
discrete_scale(aesthetic, "manual", pal, ...)
}
#' @export
scale_label_pictogram <- function(..., values, aesthetics = "label") {
picto_scale(aesthetics, values, ...)
}
#' @export
draw_key_pictogram <- function(data, params, size) {
# msg("==> draw_key_pictogram()")
#
# print(str(data, 1))
# print(str(params, 1))
if (is.null(data$label)) data$label <- "a"
textGrob(
label = data$label,
x = 0.5, y = 0.5,
rot = data$angle %||% 0,
hjust = data$hjust %||% 0,
vjust = data$vjust %||% 0.5,
gp = gpar(
col = alpha(data$colour %||% data$fill %||% "black", data$alpha),
fontfamily = data$family %||% "",
fontface = data$fontface %||% 1,
fontsize = (data$size %||% 3.88) * .pt,
lineheight = 1.5
)
)
}
#' @export
geom_pictogram <- function(mapping = NULL, data = NULL,
n_rows = 10, make_proportional = FALSE, flip = FALSE,
..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
stat = "waffle",
geom = "pictogram",
position = "identity",
show.legend = show.legend,
inherit.aes = inherit.aes,
params = list(
na.rm = na.rm,
n_rows = n_rows,
make_proportional = make_proportional,
flip = flip,
...
)
)
}
#' @export
GeomPictogram <- ggplot2::ggproto(
`_class` = "GeomPictogram",
`_inherit` = GeomText,
# required_aes = c("x", "y", "label", "colour"),
default_aes = aes(
fill = NA, alpha = NA, colour = "black",
size = 9, angle = 0, hjust = 0.5, vjust = 0.5,
family = "FontAwesome5Free-Solid", fontface = 1, lineheight = 1
),
draw_group = function(self, data, panel_params, coord,
n_rows = 10, make_proportional = FALSE, flip = FALSE,
radius = grid::unit(0, "npc")) {
# msg("Called => GeomPictogram::draw_group()")
coord <- ggplot2::coord_equal()
grobs <- GeomText$draw_panel(data, panel_params, coord, parse = FALSE, check_overlap = FALSE)
# msg("Done With => GeomPictogram::draw_group()")
ggname("geom_pictogram", grid::grobTree(children = grobs))
},
draw_panel = function(self, data, panel_params, coord,
n_rows = 10, make_proportional = FALSE, flip = FALSE, ...) {
# msg("Called => GeomPictogram::draw_panel()")
# print(str(data, 1))
coord <- ggplot2::coord_equal()
grobs <- GeomText$draw_panel(data, panel_params, coord, parse = FALSE, check_overlap = FALSE)
# msg("Done With => GeomPictogram::draw_panel()")
ggname("geom_pictogram", grid::grobTree(children = grobs))
},
draw_key = draw_key_pictogram
)

305
R/geom-waffle.R

@ -1,154 +1,155 @@
# #' Waffle (Square pie chart) Geom
# #'
# #' There are two special/critical `aes()` mappings:
# #' - `fill` (so the geom knows which column to map the country names/abbrevs to)
# #' - `values` (which column you're mapping the filling for the squares with)
# #'
# #' @md
# #' @param mapping Set of aesthetic mappings created by `aes()` or
# #' `aes_()`. If specified and `inherit.aes = TRUE` (the
# #' default), it is combined with the default mapping at the top level of the
# #' plot. You must supply `mapping` if there is no plot mapping.
# #' @param n_rows how many rows should there be in the waffle chart? default is 10
# #' @param flip If `TRUE`, flip x and y coords. n_rows then becomes n_cols.
# #' Useful to achieve waffle column chart effect. Defaults is `FALSE`.
# #' @param make_proportional compute proportions from the raw values? (i.e. each
# #' value `n` will be replaced with `n`/`sum(n)`); default is `FALSE`.
# #' @param data The data to be displayed in this layer. There are three
# #' options:
# #'
# #' If `NULL`, the default, the data is inherited from the plot
# #' data as specified in the call to `ggplot()`.
# #'
# #' A `data.frame`, or other object, will override the plot
# #' data. All objects will be fortified to produce a data frame. See
# #' `fortify()` for which variables will be created.
# #'
# #' A `function` will be called with a single argument,
# #' the plot data. The return value must be a `data.frame.`, and
# #' will be used as the layer data.
# #' @param na.rm If `FALSE`, the default, missing values are removed with
# #' a warning. If `TRUE`, missing values are silently removed.
# #' @param show.legend logical. Should this layer be included in the legends?
# #' `NA`, the default, includes if any aesthetics are mapped.
# #' `FALSE` never includes, and `TRUE` always includes.
# #' It can also be a named logical vector to finely select the aesthetics to
# #' display.
# #' @param inherit.aes If `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. `borders()`.
# #' @param ... other arguments passed on to `layer()`. These are
# #' often aesthetics, used to set an aesthetic to a fixed value, like
# #' `color = "red"` or `size = 3`. They may also be parameters
# #' to the paired geom/stat.
# #' @export
# #' @examples
# #' data.frame(
# #' parts = factor(rep(month.abb[1:3], 3), levels=month.abb[1:3]),
# #' values = c(10, 20, 30, 6, 14, 40, 30, 20, 10),
# #' fct = c(rep("Thing 1", 3), rep("Thing 2", 3), rep("Thing 3", 3))
# #' ) -> xdf
# #'
# #' ggplot(xdf, aes(fill = parts, values = values)) +
# #' geom_waffle() +
# #' facet_wrap(~fct) +
# #' coord_equal()
# geom_waffle <- function(
# mapping = NULL, data = NULL,
# n_rows = 10, flip = FALSE, make_proportional = FALSE,
# na.rm = TRUE, show.legend = NA, inherit.aes = TRUE, ...) {
#
# ggplot2::layer(
# data = data,
# mapping = mapping,
# stat = "waffle",
# geom = GeomWaffle,
# position = "identity",
# show.legend = show.legend,
# inherit.aes = inherit.aes,
# params = list(
# na.rm = TRUE,
# n_rows = n_rows,
# flip = flip,
# make_proportional = make_proportional,
# use = "fill",
# ...
# )
# )
#
# }
#
# #' @rdname geom_waffle
# #' @export
# GeomWaffle <- ggplot2::ggproto(
# `_class` = "GeomWaffle",
# `_inherit` = ggplot2::Geom,
#
# default_aes = ggplot2::aes(
# values = "values",
# fill = NA, colour = "#b2b2b2", alpha = NA,
# size = 0.125, linetype = 1, width = NA, height = NA
# ),
#
# required_aes = c("x", "y"),
#
# extra_params = c("na.rm", "width", "height", "flip", "use"),
#
# setup_data = function(data, params) {
#
# # message("Called GEOM setup_data()")
#
# waf.dat <- data #data.frame(data)#, stringsAsFactors=FALSE)
#
# # swap x and y values if flip is TRUE
# if (params$flip) {
# waf.dat$x_temp <- waf.dat$x
# waf.dat$x <- waf.dat$y
# waf.dat$y <- waf.dat$x_temp
# waf.dat$x_temp <- NULL
# }
#
# # reduce all values by 0.5
# # this allows for axis ticks to align _between_ square rows/cols
# # rather than in the middle of a row/col
# waf.dat$x <- waf.dat$x - .5
# waf.dat$y <- waf.dat$y - .5
#
# waf.dat$width <- waf.dat$width %||% params$width %||% ggplot2::resolution(waf.dat$x, FALSE)
# waf.dat$height <- waf.dat$height %||% params$height %||% ggplot2::resolution(waf.dat$y, FALSE)
#
# transform(
# waf.dat,
# xmin = x - width / 2, xmax = x + width / 2, width = NULL,
# ymin = y - height / 2, ymax = y + height / 2, height = NULL
# ) -> xdat
#
# xdat
#
# },
#
# draw_group = function(self, data, panel_params, coord,
# n_rows = 10, make_proportional = FALSE) {
#
# # message("Called GEOM draw_group()")
#
# tile_data <- data
# # tile_data$size <- border_size
# # tile_data$colour <- border_col
#
# coord <- ggplot2::coord_equal()
#
# grid::gList(
# GeomTile$draw_panel(tile_data, panel_params, coord)
# ) -> grobs
#
# ggname("geom_waffle", grid::grobTree(children = grobs))
#
# },
#
# draw_key = ggplot2::draw_key_polygon
#
# )
draw_key_waffle <- function(data, params, size, ...) { # nocov start
# msg("Called => draw_key_waffle()")
#
# print(str(data, 1))
# print(str(params, 1))
# print(str(size, 1))
# print(str(list(...), 1))
grid::roundrectGrob(
r = min(params$radius, unit(3, "pt")),
default.units = "native",
width = 0.9, height = 0.9,
name = "lkey",
gp = grid::gpar(
col = params[["color"]][[1]] %l0% params[["colour"]][1] %l0% data[["colour"]][[1]] %l0% "#00000000",
fill = alpha(data$fill %||% data$colour %||% "grey20", data$alpha),
lty = data$linetype %||% 1
)
)
} # nocov end
#' Waffle (Square pie chart) Geom
#'
#' There are two special/critical `aes()` mappings:
#' - `fill` (so the geom knows which column to map the country names/abbrevs to)
#' - `values` (which column you're mapping the filling for the squares with)
#'
#' @md
#' @param mapping Set of aesthetic mappings created by `aes()` or
#' `aes_()`. If specified and `inherit.aes = TRUE` (the
#' default), it is combined with the default mapping at the top level of the
#' plot. You must supply `mapping` if there is no plot mapping.
#' @param n_rows how many rows should there be in the waffle chart? default is 10
#' @param flip If `TRUE`, flip x and y coords. n_rows then becomes n_cols.
#' Useful to achieve waffle column chart effect. Defaults is `FALSE`.
#' @param make_proportional compute proportions from the raw values? (i.e. each
#' value `n` will be replaced with `n`/`sum(n)`); default is `FALSE`.
#' @param radius radius
#' @param data The data to be displayed in this layer. There are three
#' options:
#'
#' If `NULL`, the default, the data is inherited from the plot
#' data as specified in the call to `ggplot()`.
#'
#' A `data.frame`, or other object, will override the plot
#' data. All objects will be fortified to produce a data frame. See
#' `fortify()` for which variables will be created.
#'
#' A `function` will be called with a single argument,
#' the plot data. The return value must be a `data.frame.`, and
#' will be used as the layer data.
#' @param na.rm If `FALSE`, the default, missing values are removed with
#' a warning. If `TRUE`, missing values are silently removed.
#' @param show.legend logical. Should this layer be included in the legends?
#' `NA`, the default, includes if any aesthetics are mapped.
#' `FALSE` never includes, and `TRUE` always includes.
#' It can also be a named logical vector to finely select the aesthetics to
#' display.
#' @param inherit.aes If `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. `borders()`.
#' @param ... other arguments passed on to `layer()`. These are
#' often aesthetics, used to set an aesthetic to a fixed value, like
#' `color = "red"` or `size = 3`. They may also be parameters
#' to the paired geom/stat.
#' @export
#' @examples
#' data.frame(
#' parts = factor(rep(month.abb[1:3], 3), levels=month.abb[1:3]),
#' vals = c(10, 20, 30, 6, 14, 40, 30, 20, 10),
#' fct = c(rep("Thing 1", 3), rep("Thing 2", 3), rep("Thing 3", 3))
#' ) -> xdf
#'
#' ggplot(xdf, aes(fill = parts, values = vals)) +
#' geom_waffle() +
#' facet_wrap(~fct)
geom_waffle <- function(mapping = NULL, data = NULL,
n_rows = 10, make_proportional = FALSE, flip = FALSE,
na.rm = NA, show.legend = NA,
radius = grid::unit(0, "npc"),
inherit.aes = TRUE, ...) {
# msg("Called => geom_waffle::geom_waffle()")
# msg("Done With => geom_waffle::geom_waffle()")
layer(
stat = StatWaffle,
data = data,
mapping = mapping,
geom = GeomWaffle,
position = "identity",
show.legend = show.legend,
inherit.aes = inherit.aes,
check.param = FALSE,
params = list(
na.rm = na.rm,
n_rows = n_rows,
make_proportional = make_proportional,
flip = flip,
radius = radius,
...
)
)
}
#' @rdname geom_waffle
#' @export
GeomWaffle <- ggplot2::ggproto(
`_class` = "GeomWaffle",
`_inherit` = GeomRtile,
default_aes = ggplot2::aes(
fill = NA, alpha = NA, colour = NA,
size = 0.125, linetype = 1, width = NA, height = NA
),
draw_group = function(self, data, panel_params, coord,
n_rows = 10, make_proportional = FALSE, flip = FALSE,
radius = grid::unit(0, "npc")) {
# msg("Called => GeomWaffle::draw_group()")
coord <- ggplot2::coord_equal()
grobs <- GeomRtile$draw_panel(data, panel_params, coord, radius)
# msg("Done With => GeomWaffle::draw_group()")
ggname("geom_waffle", grid::grobTree(children = grobs))
},
draw_panel = function(self, data, panel_params, coord,
n_rows = 10, make_proportional = FALSE, flip = FALSE,
radius = grid::unit(0, "npc")) {
# msg("Called => GeomWaffle::draw_panel()")
coord <- ggplot2::coord_equal()
# grid::gList(
grobs <- GeomRtile$draw_panel(data, panel_params, coord, radius)
# ) -> grobs
# msg("Done With => GeomWaffle::draw_panel()")
ggname("geom_waffle", grid::grobTree(children = grobs))
},
draw_key = draw_key_waffle
)

143
R/stat-pictogram.R

@ -1,143 +0,0 @@
# #' @rdname geom_pictogram
# #' @export
# stat_pictogram <- function(mapping = NULL, data = NULL,
# n_rows = 10, make_proportional = FALSE,
# na.rm = NA, show.legend = NA,
# inherit.aes = TRUE, ...) {
#
# layer(
# stat = StatPictogram,
# data = data,
# mapping = mapping,
# geom = "pictogram",
# position = "identity",
# show.legend = show.legend,
# inherit.aes = inherit.aes,
# params = list(
# na.rm = na.rm,
# n_rows = n_rows,
# make_proportional = make_proportional,
# ...
# )
# )
# }
#
# #' @rdname geom_pictogram
# #' @export
# StatPictogram <- ggplot2::ggproto(
# `_class` = "StatPictogram",
# `_inherit` = ggplot2::Stat,
#
# required_aes = c("colour", "values", "fa_type", "fa_glyph"),
# extra_params = c("na.rm", "width", "height", "flip", "use"),
#
# setup_params = function(data, params) {
# # message("Called StatPictogram::setup_params()")
# params
# },
#
# setup_data = function(data, params) {
# # message("Called StatPictogram::setup_data()")
# # print(str(data, 1))
# data
# },
#
# compute_layer = function(self, data, params, panels) {
#
# # message("Called StatPictogram::compute_layer()")
# # print(str(data, 1))
#
# use <- params[["use"]]
#
# if (inherits(data[[use]], "factor")) {
# flvls <- levels(data[[use]])
# } else {
# flvls <- levels(factor(data[[use]]))
# }
#
# tr1 <- data[c(use, "fa_glyph", "fa_type")]
# tr1 <- tr1[!duplicated(tr1), ]
#
# gtrans <- tr1[, "fa_glyph"]
# names(gtrans) <- tr1[, use]
#
# ttrans <- tr1[, "fa_type"]
# names(ttrans) <- tr1[, use]
#
# # print(str(tr1, 1))
#
# p <- split(data, data$PANEL)
#
# lapply(p, function(.x) {
#
# parts_vec <- unlist(sapply(1:length(.x[[use]]), function(i) {
# rep(as.character(.x[[use]][i]), .x[["values"]][i])
# }))
#
# pgrp_vec <- unlist(sapply(1:length(.x[[use]]), function(i) {
# rep(.x$group, .x[[use]][i])
# }))
#
# expand.grid(
# y = 1:params$n_rows,
# x = seq_len((ceiling(sum(.x[["values"]]) / params$n_rows)))#,
# # stringsAsFactors = FALSE
# ) -> tdf
#
# parts_vec <- c(parts_vec, rep(NA, nrow(tdf) - length(parts_vec)))
#
# # tdf$parts <- parts_vec
# tdf[["values"]] <- parts_vec
# tdf[[use]] <- parts_vec
#
# tdf[["fa_glyph"]] <- gtrans[tdf[[use]]]
# tdf[["fa_type"]] <- ttrans[tdf[[use]]]
#
# tdf[["PANEL"]] <- .x[["PANEL"]][1]
# tdf[["group"]] <- 1:nrow(tdf)
#
# tdf <- tdf[sapply(tdf[[use]], function(x) !is.na(x)),]
#
# tdf
#
# }) -> p
#
# p <- plyr::rbind.fill(p)
# p[[use]] <- factor(p[[use]], levels=flvls)
#
# # print(str(p, 1))
#
# p
#
# },
#
# finish_layer = function(self, data, params) {
# # message("Called StatPictogram::finish_layer()")
# self$default_aes[["fa_glyph"]] <- "square"
# # print(str(data,1))
# # print(str(params, 1))
# data
# },
#
# compute_panel = function(self, data, scales, na.rm = FALSE,
# n_rows = 10, make_proportional = FALSE) {
#
# # message("Called StatPictogram::compute_panel()")
#
# ggproto_parent(Stat, self)$compute_panel(
# data, scales,
# n_rows = n_rows,
# make_proportional = make_proportional,
# na.rm = na.rm
# )
#
# },
#
# aesthetics = function(self) {
# # message("Called StatPictogram::aesthetics()")
# c(union(self$required_aes, names(self$default_aes)), "group")
# }
#
#
# )
#

286
R/stat-waffle.R

@ -1,98 +1,188 @@
# #' @rdname geom_waffle
# #' @export
# stat_waffle<- function(mapping = NULL, data = NULL,
# n_rows = 10, make_proportional = FALSE,
# na.rm = NA, show.legend = NA,
# inherit.aes = TRUE, ...) {
#
# layer(
# stat = StatWaffle,
# data = data,
# mapping = mapping,
# geom = "waffle",
# position = "identity",
# show.legend = show.legend,
# inherit.aes = inherit.aes,
# params = list(
# na.rm = na.rm,
# n_rows = n_rows,
# make_proportional = make_proportional,
# ...
# )
# )
# }
#
# #' @rdname geom_waffle
# #' @export
# StatWaffle <- ggplot2::ggproto(
# `_class` = "StatWaffle",
# `_inherit` = ggplot2::Stat,
#
# required_aes = c("fill", "values"),
#
# extra_params = c("na.rm", "width", "height", "flip", "use"),
#
# compute_layer = function(self, data, params, panels) {
#
# use <- params[["use"]]
#
# if (inherits(data[[use]], "factor")) {
# flvls <- levels(data[[use]])
# } else {
# flvls <- levels(factor(data[[use]]))
# }
#
# p <- split(data, data$PANEL)
#
# lapply(p, function(.x) {
#
# parts_vec <- unlist(sapply(1:length(.x[[use]]), function(i) {
# rep(as.character(.x[[use]][i]), .x[["values"]][i])
# }))
#
# pgrp_vec <- unlist(sapply(1:length(.x[[use]]), function(i) {
# rep(.x$group, .x[[use]][i])
# }))
#
# expand.grid(
# y = 1:params$n_rows,
# x = seq_len((ceiling(sum(.x[["values"]]) / params$n_rows)))#,
# # stringsAsFactors = FALSE
# ) -> tdf
#
# parts_vec <- c(parts_vec, rep(NA, nrow(tdf)-length(parts_vec)))
#
# # tdf$parts <- parts_vec
# tdf[["values"]] <- NA
# tdf[[use]] <- parts_vec
# tdf[["PANEL"]] <- .x[["PANEL"]][1]
# tdf[["group"]] <- 1:nrow(tdf)
#
# tdf <- tdf[sapply(tdf[[use]], function(x) !is.na(x)),]
#
# }) -> p
#
# p <- plyr::rbind.fill(p)
# p[[use]] <- factor(p[[use]], levels=flvls)
#
# # print(str(p))
#
# p
#
# },
#
# compute_panel = function(self, data, scales, na.rm = FALSE,
# n_rows = 10, make_proportional = FALSE) {
#
# # message("Called STAT compute_panel()")
#
# ggproto_parent(Stat, self)$compute_panel(
# data, scales,
# n_rows = 10,
# make_proportional = FALSE
# )
#
# }
#
# )
#
#' @rdname geom_waffle
#' @export
stat_waffle <- function(mapping = NULL, data = NULL, geom = "waffle",
n_rows = 10, make_proportional = FALSE, flip = FALSE,
radius = grid::unit(0, "npc"),
na.rm = NA, show.legend = NA,
inherit.aes = TRUE, ...) {
# msg("Called => stat_waffle::stat_waffle()")
# msg("Done With => stat_waffle::stat_waffle()")
layer(
stat = StatWaffle,
data = data,
mapping = mapping,
geom = geom,
position = "identity",
show.legend = show.legend,
inherit.aes = inherit.aes,
check.param = FALSE,
params = list(
na.rm = na.rm,
n_rows = n_rows,
make_proportional = make_proportional,
flip = flip,
radius = radius,
...
)
)
}
#' @rdname geom_waffle
#' @export
StatWaffle <- ggplot2::ggproto(
`_class` = "StatWaffle",
`_inherit` = ggplot2::Stat,
extra_params = c("na.rm", "n_rows", "make_proportional", "flip", "radius"),
required_aes = c("fill", "values", "colour", "label"),
setup_params = function(data, params) {
# msg("Called => StatWaffle::setup_params()")
# msg("Done With => StatWaffle::setup_params()")
params
},
setup_data = function(data, params) {
# msg("Called => StatWaffle::setup_data()")
#
# print(str(data, 1))
# print(str(params, 1))
use <- if ("label" %in% names(data)) "label" else "fill"
if (inherits(data[[use]], "factor")) {
flvls <- levels(data[[use]])
} else {
flvls <- levels(factor(data[[use]]))
}
if (inherits(data[["colour"]], "factor")) {
clvls <- levels(data[["colour"]])
} else {
clvls <- levels(factor(data[["colour"]]))
}
if (!("colour" %in% names(data))) {
if ("colour" %in% names(params)) {
data[["colour"]] <- params[["colour"]]
} else {
data[["colour"]] <- "white"
}
clvls <- levels(factor(data[["colour"]]))
} else {
if (any(is.na(as.character(data[["colour"]])))) {
data[["colour"]] <- "white"
clvls <- levels(factor(data[["colour"]]))
} else {
data[["colour"]] <- as.character(data[["colour"]])
}
}
# msg(" => StatWaffle::setup_data() : colour")
# print(str(data, 1))
p <- split(data, data$PANEL)
lapply(p, function(.x) {
if (params[["make_proportional"]]) {
.x[["values"]] <- .x[["values"]] / sum(.x[["values"]])
.x[["values"]] <- round_preserve_sum(.x[["values"]], digits = 2)
.x[["values"]] <- as.integer(.x[["values"]] * 100)
}
parts_vec <- unlist(sapply(1:length(.x[[use]]), function(i) {
rep(as.character(.x[[use]][i]), .x[["values"]][i])
}))
pgrp_vec <- unlist(sapply(1:length(.x[[use]]), function(i) {
rep(.x[["group"]], .x[["values"]][i])
}))
# print(str(.x, 1))
colour_vec <- unlist(sapply(1:length(.x[[use]]), function(i) {
rep(.x[["colour"]][i], .x[["values"]][i])
}))
expand.grid(
y = 1:params$n_rows,
x = seq_len((ceiling(sum(.x[["values"]]) / params$n_rows)))#,
# stringsAsFactors = FALSE
) -> tdf
parts_vec <- c(parts_vec, rep(NA, nrow(tdf)-length(parts_vec)))
colour_vec <- c(colour_vec, rep(NA, nrow(tdf)-length(colour_vec)))
# tdf$parts <- parts_vec
tdf[["values"]] <- NA
tdf[["colour"]] <- colour_vec
tdf[[use]] <- parts_vec
tdf[["PANEL"]] <- .x[["PANEL"]][1]
tdf[["group"]] <- 1:nrow(tdf)
tdf <- tdf[sapply(tdf[[use]], function(x) !is.na(x)),]
}) -> p
p <- plyr::rbind.fill(p)
p[[use]] <- factor(p[[use]], levels=flvls)
p[["colour"]] <- factor(p[["colour"]], levels = clvls)
# print(str(p, 1))
#
# msg("Done With => StatWaffle::setup_data()")
# data
wdat <- p
if (params$flip) {
x_temp <- wdat$x
wdat$x <- wdat$y
wdat$y <- x_temp
x_temp <- NULL
}
wdat$width <- wdat$width %||% params$width %||% ggplot2::resolution(wdat$x, FALSE)
wdat$height <- wdat$height %||% params$height %||% ggplot2::resolution(wdat$y, FALSE)
transform(
wdat,
xmin = x - width / 2,
xmax = x + width / 2,
width = NULL,
ymin = y - height / 2,
ymax = y + height / 2,
height = NULL
) -> p
p
},
compute_layer = function(self, data, params, layout) {
# msg("Called => StatWaffle::compute_layer()")
# print(str(data, 1))
# print(str(params, 1))
# msg("Done With => StatWaffle::compute_layer()")
data
},
finish_layer = function(self, data, params) {
# msg("Called => StatWaffle::finish_layer()")
# msg("Done With => StatWaffle::finish_layer()")
data
},
compute_panel = function(self, data, scales, ...) {
# msg("Called => StatWaffle::compute_panel()")
# msg("Done With => StatWaffle::compute_panel()")
data
}
)

355
R/sw2.R

@ -1,355 +0,0 @@
draw_key_waffle <- function(data, params, size, ...) { # nocov start
# msg("Called => draw_key_waffle()")
#
# print(str(data, 1))
# print(str(params, 1))
# print(str(size, 1))
# print(str(list(...), 1))
grid::roundrectGrob(
r = min(params$radius, unit(3, "pt")),
default.units = "native",
width = 0.9, height = 0.9,
name = "lkey",
gp = grid::gpar(
col = params[["color"]][[1]] %l0% params[["colour"]][1] %l0% data[["colour"]][[1]] %l0% "#00000000",
fill = alpha(data$fill %||% data$colour %||% "grey20", data$alpha),
lty = data$linetype %||% 1
)
)
} # nocov end
#' Waffle (Square pie chart) Geom
#'
#' There are two special/critical `aes()` mappings:
#' - `fill` (so the geom knows which column to map the country names/abbrevs to)
#' - `values` (which column you're mapping the filling for the squares with)
#'
#' @md
#' @param mapping Set of aesthetic mappings created by `aes()` or
#' `aes_()`. If specified and `inherit.aes = TRUE` (the
#' default), it is combined with the default mapping at the top level of the
#' plot. You must supply `mapping` if there is no plot mapping.
#' @param n_rows how many rows should there be in the waffle chart? default is 10
#' @param flip If `TRUE`, flip x and y coords. n_rows then becomes n_cols.
#' Useful to achieve waffle column chart effect. Defaults is `FALSE`.
#' @param make_proportional compute proportions from the raw values? (i.e. each
#' value `n` will be replaced with `n`/`sum(n)`); default is `FALSE`.
#' @param radius radius
#' @param data The data to be displayed in this layer. There are three
#' options:
#'
#' If `NULL`, the default, the data is inherited from the plot
#' data as specified in the call to `ggplot()`.
#'
#' A `data.frame`, or other object, will override the plot
#' data. All objects will be fortified to produce a data frame. See
#' `fortify()` for which variables will be created.
#'
#' A `function` will be called with a single argument,
#' the plot data. The return value must be a `data.frame.`, and
#' will be used as the layer data.
#' @param na.rm If `FALSE`, the default, missing values are removed with
#' a warning. If `TRUE`, missing values are silently removed.
#' @param show.legend logical. Should this layer be included in the legends?
#' `NA`, the default, includes if any aesthetics are mapped.
#' `FALSE` never includes, and `TRUE` always includes.
#' It can also be a named logical vector to finely select the aesthetics to
#' display.
#' @param inherit.aes If `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. `borders()`.
#' @param ... other arguments passed on to `layer()`. These are
#' often aesthetics, used to set an aesthetic to a fixed value, like
#' `color = "red"` or `size = 3`. They may also be parameters
#' to the paired geom/stat.
#' @export
#' @examples
#' data.frame(
#' parts = factor(rep(month.abb[1:3], 3), levels=month.abb[1:3]),
#' vals = c(10, 20, 30, 6, 14, 40, 30, 20, 10),
#' fct = c(rep("Thing 1", 3), rep("Thing 2", 3), rep("Thing 3", 3))
#' ) -> xdf
#'
#' ggplot(xdf, aes(fill = parts, values = vals)) +
#' geom_waffle() +
#' facet_wrap(~fct)
geom_waffle <- function(mapping = NULL, data = NULL,
n_rows = 10, make_proportional = FALSE,
na.rm = NA, show.legend = NA, flip = FALSE,
radius = grid::unit(0, "npc"),
inherit.aes = TRUE, ...) {
# msg("Called => geom_waffle::geom_waffle()")
# msg("Done With => geom_waffle::geom_waffle()")
layer(
stat = StatWaffle,
data = data,
mapping = mapping,
geom = GeomWaffle,
position = "identity",
show.legend = show.legend,
inherit.aes = inherit.aes,
check.param = FALSE,
params = list(
na.rm = na.rm,
n_rows = n_rows,
make_proportional = make_proportional,
flip = flip,
radius = radius,
...
)
)
}
#' @rdname geom_waffle
#' @export
GeomWaffle <- ggplot2::ggproto(
`_class` = "GeomWaffle",
`_inherit` = GeomRtile,
default_aes = ggplot2::aes(
fill = NA, alpha = NA, colour = NA,
size = 0.125, linetype = 1, width = NA, height = NA
),
draw_group = function(self, data, panel_params, coord,
n_rows = 10, make_proportional = FALSE, flip = FALSE,
radius = grid::unit(0, "npc")) {
# msg("Called => GeomWaffle::draw_group()")
coord <- ggplot2::coord_equal()
grobs <- GeomRtile$draw_panel(data, panel_params, coord, radius)
# msg("Done With => GeomWaffle::draw_group()")
ggname("geom_waffle", grid::grobTree(children = grobs))
},
draw_panel = function(self, data, panel_params, coord,
n_rows = 10, make_proportional = FALSE, flip = FALSE,
radius = grid::unit(0, "npc")) {
# msg("Called => GeomWaffle::draw_panel()")
coord <- ggplot2::coord_equal()
# grid::gList(
grobs <- GeomRtile$draw_panel(data, panel_params, coord, radius)
# ) -> grobs
# msg("Done With => GeomWaffle::draw_panel()")
ggname("geom_waffle", grid::grobTree(children = grobs))
},
draw_key = draw_key_waffle
)
#' @rdname geom_waffle
#' @export
stat_waffle <- function(mapping = NULL, data = NULL, geom = "blank",
n_rows = 10, make_proportional = FALSE, flip = FALSE,
radius = grid::unit(0, "npc"),
na.rm = NA, show.legend = NA,
inherit.aes = TRUE, ...) {
# msg("Called => stat_waffle::stat_waffle()")
# msg("Done With => stat_waffle::stat_waffle()")
layer(
stat = StatWaffle,
data = data,
mapping = mapping,
geom = geom,
position = "identity",
show.legend = show.legend,
inherit.aes = inherit.aes,
check.param = FALSE,
params = list(
na.rm = na.rm,
n_rows = n_rows,
make_proportional = make_proportional,
flip = flip,
radius = radius,
...
)
)
}
#' @rdname geom_waffle
#' @export
StatWaffle <- ggplot2::ggproto(
`_class` = "StatWaffle",
`_inherit` = ggplot2::Stat,
extra_params = c("na.rm", "n_rows", "make_proportional", "flip", "radius"),
required_aes = c("fill", "values", "colour"),
setup_params = function(data, params) {
# msg("Called => StatWaffle::setup_params()")
# msg("Done With => StatWaffle::setup_params()")
params
},
setup_data = function(data, params) {
# msg("Called => StatWaffle::setup_data()")
#
# print(str(data, 1))
# print(str(params, 1))
use <- "fill"
if (inherits(data[[use]], "factor")) {
flvls <- levels(data[[use]])
} else {
flvls <- levels(factor(data[[use]]))
}
if (inherits(data[["colour"]], "factor")) {
clvls <- levels(data[["colour"]])
} else {
clvls <- levels(factor(data[["colour"]]))
}
if (!("colour" %in% names(data))) {
data[["colour"]] <- "white"
} else {
if (any(is.na(as.character(data[["colour"]])))) {
data[["colour"]] <- "white"
} else {
data[["colour"]] <- as.character(data[["colour"]])
}
}
p <- split(data, data$PANEL)
lapply(p, function(.x) {
if (params[["make_proportional"]]) {
.x[["values"]] <- .x[["values"]] / sum(.x[["values"]])
.x[["values"]] <- round_preserve_sum(.x[["values"]], digits = 2)
.x[["values"]] <- as.integer(.x[["values"]] * 100)
}
parts_vec <- unlist(sapply(1:length(.x[[use]]), function(i) {
rep(as.character(.x[[use]][i]), .x[["values"]][i])
}))
pgrp_vec <- unlist(sapply(1:length(.x[[use]]), function(i) {
rep(.x$group, .x[["values"]][i])
}))
# print(str(.x, 1))
colour_vec <- unlist(sapply(1:length(.x[[use]]), function(i) {
rep(.x[["colour"]][i], .x[["values"]][i])
}))
expand.grid(
y = 1:params$n_rows,
x = seq_len((ceiling(sum(.x[["values"]]) / params$n_rows)))#,
# stringsAsFactors = FALSE
) -> tdf
parts_vec <- c(parts_vec, rep(NA, nrow(tdf)-length(parts_vec)))
colour_vec <- c(colour_vec, rep(NA, nrow(tdf)-length(colour_vec)))
# tdf$parts <- parts_vec
tdf[["values"]] <- NA
tdf[["colour"]] <- colour_vec
tdf[[use]] <- parts_vec
tdf[["PANEL"]] <- .x[["PANEL"]][1]
tdf[["group"]] <- 1:nrow(tdf)
tdf <- tdf[sapply(tdf[[use]], function(x) !is.na(x)),]
}) -> p
p <- plyr::rbind.fill(p)
p[[use]] <- factor(p[[use]], levels=flvls)
p[["colour"]] <- factor(p[["colour"]], levels = clvls)
# print(str(p, 1))
#
# msg("Done With => StatWaffle::setup_data()")
# data
wdat <- p
if (params$flip) {
x_temp <- wdat$x
wdat$x <- wdat$y
wdat$y <- x_temp
x_temp <- NULL
}
wdat$width <- wdat$width %||% params$width %||% ggplot2::resolution(wdat$x, FALSE)
wdat$height <- wdat$height %||% params$height %||% ggplot2::resolution(wdat$y, FALSE)
transform(
wdat,
xmin = x - width / 2,
xmax = x + width / 2,
width = NULL,
ymin = y - height / 2,
ymax = y + height / 2,
height = NULL
) -> p
p
},
compute_layer = function(self, data, params, layout) {
# msg("Called => StatWaffle::compute_layer()")
# print(str(data, 1))
# print(str(params, 1))
# msg("Done With => StatWaffle::compute_layer()")
data
},
finish_layer = function(self, data, params) {
# msg("Called => StatWaffle::finish_layer()")
# msg("Done With => StatWaffle::finish_layer()")
data
},
compute_panel = function(self, data, scales, ...) {
# msg("Called => StatWaffle::compute_panel()")
# msg("Done With => StatWaffle::compute_panel()")
data
}
)

3
R/utils.r

@ -7,6 +7,9 @@ round_preserve_sum <- function(x, digits = 0) {
y / up
}
is_missing_arg <- function(x) identical(x, quote(expr = ))
# VIA: http://stackoverflow.com/q/13294952/1457051
rbind_gtable_max <- function(...) {

3
R/waffle-package.R

@ -19,7 +19,10 @@
#' @importFrom ggplot2 geom_point geom_text scale_color_manual guides theme labs
#' @importFrom ggplot2 scale_x_continuous scale_y_continuous coord_equal theme_bw
#' @importFrom ggplot2 aes guide_legend element_rect element_blank element_text layer
#' @importFrom ggplot2 discrete_scale
#' @importFrom grid arrow unit grid.newpage grid.draw unit.c unit.pmax unit.pmin
#' @importFrom grid textGrob gpar grobTree roundrectGrob
#' @importFrom extrafont ttf_import font_import choose_font
#' @importFrom stats setNames
#' @importFrom rlang is_missing
NULL

80
README.Rmd

@ -2,7 +2,7 @@
output: rmarkdown::github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(echo = TRUE, collapse = TRUE, message = FALSE, warning = FALSE, error = FALSE, fig.retina = 2)
knitr::opts_chunk$set(echo = TRUE, collapse = TRUE, message = FALSE, warning = FALSE, error = FALSE, cache = TRUE, fig.retina = 2)
```
[![Build Status](https://travis-ci.org/hrbrmstr/waffle.svg)](https://travis-ci.org/hrbrmstr/waffle)
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/waffle)](https://cran.r-project.org/package=waffle)
@ -39,14 +39,88 @@ options(width = 120)
## Usage
```{r s3}
```{r s3, cache=FALSE}
library(waffle)
library(waffle)
library(magrittr)
library(hrbrthemes)
library(ggplot2)
library(dplyr)
library(waffle)
# current verison
packageVersion("waffle")
```
### Geoms! (WIP)
### Some new bits up first
```{r fig.width=8, fig.height=6}
data.frame(
parts = factor(rep(month.abb[1:3], 3), levels=month.abb[1:3]),
vals = c(10, 20, 30, 6, 14, 40, 30, 20, 10),
col = rep(c("blue", "black", "red"), 3),
fct = c(rep("Thing 1", 3),
rep("Thing 2", 3),
rep("Thing 3", 3))
) -> xdf
xdf %>%
count(parts, wt = vals) %>%
ggplot(aes(fill = parts, values = n)) +
geom_waffle(n_rows = 20, size = 0.33, colour = "white", flip = TRUE) +
scale_fill_manual(
name = NULL,
values = c("#a40000", "#c68958", "#ae6056"),
labels = c("Fruit", "Sammich", "Pizza")
) +
coord_equal() +
theme_ipsum_rc(grid="") +
theme_enhance_waffle()
xdf %>%
count(parts, wt = vals) %>%
ggplot(aes(label = parts, values = n)) +
geom_pictogram(n_rows = 10, aes(colour = parts), flip = TRUE, make_proportional = TRUE) +
scale_color_manual(
name = NULL,
values = c("#a40000", "#c68958", "#ae6056"),
labels = c("Fruit", "Sammich", "Pizza")
) +
scale_label_pictogram(
name = NULL,
values = c("apple-alt", "bread-slice", "pizza-slice"),
labels = c("Fruit", "Sammich", "Pizza")
) +
coord_equal() +
theme_ipsum_rc(grid="") +
theme_enhance_waffle() +
theme(legend.key.height = unit(2.25, "line")) +
theme(legend.text = element_text(size = 10, hjust = 0, vjust = 0.75))
xdf %>%
count(parts, wt = vals) %>%
ggplot(aes(label = parts, values = n)) +
geom_pictogram(
n_rows = 20, size = 6, aes(colour = parts), flip = TRUE,
family = "FontAwesome5Brands-Regular"
) +
scale_color_manual(
name = NULL,
values = c("#073f9c", "black", "#f34323"),
labels = c("BitBucket", "GitHub", "Other")
) +
scale_label_pictogram(
name = NULL,
values = c("bitbucket", "github", "git-alt"),
labels = c("BitBucket", "GitHub", "Other")
) +
coord_equal() +
theme_ipsum_rc(grid="") +
theme_enhance_waffle() +
theme(legend.text = element_text(hjust = 0, vjust = 1))
```
### Geoms!
```{r geoms, fig.width=6, fig.height=8, fig.retina=2}
library(hrbrthemes)

96
README.md

@ -51,13 +51,99 @@ devtools::install_github("hrbrmstr/waffle")
``` r
library(waffle)
library(waffle)
library(magrittr)
library(hrbrthemes)
library(ggplot2)
library(dplyr)
library(waffle)
# current verison
packageVersion("waffle")
## [1] '1.0.1'
```
### Geoms\! (WIP)
### Some new bits up first
``` r
data.frame(
parts = factor(rep(month.abb[1:3], 3), levels=month.abb[1:3]),
vals = c(10, 20, 30, 6, 14, 40, 30, 20, 10),
col = rep(c("blue", "black", "red"), 3),
fct = c(rep("Thing 1", 3),
rep("Thing 2", 3),
rep("Thing 3", 3))
) -> xdf
xdf %>%
count(parts, wt = vals) %>%
ggplot(aes(fill = parts, values = n)) +
geom_waffle(n_rows = 20, size = 0.33, colour = "white", flip = TRUE) +
scale_fill_manual(
name = NULL,
values = c("#a40000", "#c68958", "#ae6056"),
labels = c("Fruit", "Sammich", "Pizza")
) +
coord_equal() +
theme_ipsum_rc(grid="") +
theme_enhance_waffle()
```
<img src="README_files/figure-gfm/unnamed-chunk-2-1.png" width="768" />
``` r
xdf %>%
count(parts, wt = vals) %>%
ggplot(aes(label = parts, values = n)) +
geom_pictogram(n_rows = 10, aes(colour = parts), flip = TRUE, make_proportional = TRUE) +
scale_color_manual(
name = NULL,
values = c("#a40000", "#c68958", "#ae6056"),
labels = c("Fruit", "Sammich", "Pizza")
) +
scale_label_pictogram(
name = NULL,
values = c("apple-alt", "bread-slice", "pizza-slice"),
labels = c("Fruit", "Sammich", "Pizza")
) +
coord_equal() +
theme_ipsum_rc(grid="") +
theme_enhance_waffle() +
theme(legend.key.height = unit(2.25, "line")) +
theme(legend.text = element_text(size = 10, hjust = 0, vjust = 0.75))
```
<img src="README_files/figure-gfm/unnamed-chunk-2-2.png" width="768" />
``` r
xdf %>%
count(parts, wt = vals) %>%
ggplot(aes(label = parts, values = n)) +
geom_pictogram(
n_rows = 20, size = 6, aes(colour = parts), flip = TRUE,
family = "FontAwesome5Brands-Regular"
) +
scale_color_manual(
name = NULL,
values = c("#073f9c", "black", "#f34323"),
labels = c("BitBucket", "GitHub", "Other")
) +
scale_label_pictogram(
name = NULL,
values = c("bitbucket", "github", "git-alt"),
labels = c("BitBucket", "GitHub", "Other")
) +
coord_equal() +
theme_ipsum_rc(grid="") +
theme_enhance_waffle() +
theme(legend.text = element_text(hjust = 0, vjust = 1))
```
<img src="README_files/figure-gfm/unnamed-chunk-2-3.png" width="768" />
### Geoms\!
``` r
library(hrbrthemes)
@ -289,10 +375,10 @@ iron(A, B, C)
cloc::cloc_pkg_md()
```
| Lang | \# Files | (%) | LoC | (%) | Blank lines | (%) | \# Lines | (%) |
| :--- | -------: | --: | --: | ---: | ----------: | ---: | -------: | ---: |
| R | 18 | 0.9 | 545 | 0.63 | 202 | 0.61 | 1011 | 0.85 |
| Rmd | 2 | 0.1 | 317 | 0.37 | 130 | 0.39 | 181 | 0.15 |
| Lang | \# Files | (%) | LoC | (%) | Blank lines | (%) | \# Lines | (%) |
| :--- | -------: | ---: | --: | ---: | ----------: | ---: | -------: | ---: |
| R | 16 | 0.89 | 628 | 0.62 | 209 | 0.61 | 373 | 0.67 |
| Rmd | 2 | 0.11 | 383 | 0.38 | 135 | 0.39 | 184 | 0.33 |
## Code of Conduct

14
README_cache/gfm/__packages

@ -0,0 +1,14 @@
base
ggplot2
waffle
magrittr
hrbrthemes
dplyr
tidyverse
tibble
tidyr
readr
purrr
stringr
forcats
extrafont

BIN
README_cache/gfm/f5_4ad4736778ddf27b4931aadaacaac8ac.RData

Binary file not shown.

0
README_cache/gfm/f5_4ad4736778ddf27b4931aadaacaac8ac.rdb

BIN
README_cache/gfm/f5_4ad4736778ddf27b4931aadaacaac8ac.rdx

Binary file not shown.

BIN
README_cache/gfm/f8_64fe7a35a243319e74cbbdad7227be28.RData

Binary file not shown.

BIN
README_cache/gfm/f8_64fe7a35a243319e74cbbdad7227be28.rdb

Binary file not shown.

BIN
README_cache/gfm/f8_64fe7a35a243319e74cbbdad7227be28.rdx

Binary file not shown.

BIN
README_cache/gfm/fct_fa2af6d9218db86d6d178d3bbd2466a4.RData

Binary file not shown.

0
README_cache/gfm/fct_fa2af6d9218db86d6d178d3bbd2466a4.rdb

BIN
README_cache/gfm/fct_fa2af6d9218db86d6d178d3bbd2466a4.rdx

Binary file not shown.

BIN
README_cache/gfm/fig0_a8d5a1e257eb143faece4bed088744ca.RData

Binary file not shown.

BIN
README_cache/gfm/fig0_a8d5a1e257eb143faece4bed088744ca.rdb

Binary file not shown.

BIN
README_cache/gfm/fig0_a8d5a1e257eb143faece4bed088744ca.rdx

Binary file not shown.

BIN
README_cache/gfm/fig1_203fd0f3bc8c6069277b2a93c9fafa60.RData

Binary file not shown.

BIN
README_cache/gfm/fig1_203fd0f3bc8c6069277b2a93c9fafa60.rdb

Binary file not shown.

BIN
README_cache/gfm/fig1_203fd0f3bc8c6069277b2a93c9fafa60.rdx

Binary file not shown.

BIN
README_cache/gfm/fig2_76e8ea5d53b53979b80bafc55421117f.RData

Binary file not shown.

0
README_cache/gfm/fig2_76e8ea5d53b53979b80bafc55421117f.rdb

BIN
README_cache/gfm/fig2_76e8ea5d53b53979b80bafc55421117f.rdx

Binary file not shown.

BIN
README_cache/gfm/fig3_a2a7a52b2ec33fcf5202e1f938eaab82.RData

Binary file not shown.

0
README_cache/gfm/fig3_a2a7a52b2ec33fcf5202e1f938eaab82.rdb

BIN
README_cache/gfm/fig3_a2a7a52b2ec33fcf5202e1f938eaab82.rdx

Binary file not shown.

BIN
README_cache/gfm/fig4_ac3e92ba84f83b56b7881968998decfa.RData

Binary file not shown.

0
README_cache/gfm/fig4_ac3e92ba84f83b56b7881968998decfa.rdb

BIN
README_cache/gfm/fig4_ac3e92ba84f83b56b7881968998decfa.rdx

Binary file not shown.

BIN
README_cache/gfm/fig4a_6cd3b719ae840625775a57ab9b9c2ae5.RData

Binary file not shown.

0
README_cache/gfm/fig4a_6cd3b719ae840625775a57ab9b9c2ae5.rdb

BIN
README_cache/gfm/fig4a_6cd3b719ae840625775a57ab9b9c2ae5.rdx

Binary file not shown.

BIN
README_cache/gfm/geoms_908ed3f0fa75ec43dbfcee122a632d10.RData

Binary file not shown.

BIN
README_cache/gfm/geoms_908ed3f0fa75ec43dbfcee122a632d10.rdb

Binary file not shown.

BIN
README_cache/gfm/geoms_908ed3f0fa75ec43dbfcee122a632d10.rdx

Binary file not shown.

BIN
README_cache/gfm/ingredients_03d07729b8c87f59927b3d580f1db2f9.RData

Binary file not shown.

0
README_cache/gfm/ingredients_03d07729b8c87f59927b3d580f1db2f9.rdb

BIN
README_cache/gfm/ingredients_03d07729b8c87f59927b3d580f1db2f9.rdx

Binary file not shown.

BIN
README_cache/gfm/medkit0_7c3701449a0fd4fc396c95ab06356811.RData

Binary file not shown.

0
README_cache/gfm/medkit0_7c3701449a0fd4fc396c95ab06356811.rdb

BIN
README_cache/gfm/medkit0_7c3701449a0fd4fc396c95ab06356811.rdx

Binary file not shown.

BIN
README_cache/gfm/medkit_660b2606a5fa68d594bdd6998a182c35.RData

Binary file not shown.

0
README_cache/gfm/medkit_660b2606a5fa68d594bdd6998a182c35.rdb

BIN
README_cache/gfm/medkit_660b2606a5fa68d594bdd6998a182c35.rdx

Binary file not shown.

BIN
README_cache/gfm/no_fct_e57ef189ba393cd466eb8345744894b7.RData

Binary file not shown.

0
README_cache/gfm/no_fct_e57ef189ba393cd466eb8345744894b7.rdb

BIN
README_cache/gfm/no_fct_e57ef189ba393cd466eb8345744894b7.rdx

Binary file not shown.

BIN
README_cache/gfm/nstall-ex_47a60990e2d319f8433b2210a6890028.RData

Binary file not shown.

0
README_cache/gfm/nstall-ex_47a60990e2d319f8433b2210a6890028.rdb

BIN
README_cache/gfm/nstall-ex_47a60990e2d319f8433b2210a6890028.rdx

Binary file not shown.

BIN
README_cache/gfm/s2_66cee9d85dc6a99ef20315ebeab21b5b.RData

Binary file not shown.

0
README_cache/gfm/s2_66cee9d85dc6a99ef20315ebeab21b5b.rdb

BIN
README_cache/gfm/s2_66cee9d85dc6a99ef20315ebeab21b5b.rdx

Binary file not shown.

BIN
README_cache/gfm/s4_f7b6c188da6eb517c5c45416691b5e7f.RData

Binary file not shown.

BIN
README_cache/gfm/s4_f7b6c188da6eb517c5c45416691b5e7f.rdb

Binary file not shown.

BIN
README_cache/gfm/s4_f7b6c188da6eb517c5c45416691b5e7f.rdx

Binary file not shown.

BIN
README_cache/gfm/s5_f40630030d69783eead525c32f428060.RData

Binary file not shown.

BIN
README_cache/gfm/s5_f40630030d69783eead525c32f428060.rdb

Binary file not shown.

BIN
README_cache/gfm/s5_f40630030d69783eead525c32f428060.rdx

Binary file not shown.

BIN
README_cache/gfm/s6_ff0c8f3ad2fcc652170b8bf9592357d3.RData

Binary file not shown.

BIN
README_cache/gfm/s6_ff0c8f3ad2fcc652170b8bf9592357d3.rdb

Binary file not shown.

BIN
README_cache/gfm/s6_ff0c8f3ad2fcc652170b8bf9592357d3.rdx

Binary file not shown.

BIN
README_cache/gfm/t1_f04db1ac25ff0686d88ab58a3f2d4d70.RData

Binary file not shown.

0
README_cache/gfm/t1_f04db1ac25ff0686d88ab58a3f2d4d70.rdb

BIN
README_cache/gfm/t1_f04db1ac25ff0686d88ab58a3f2d4d70.rdx

Binary file not shown.

BIN
README_cache/gfm/t2_733bbc8dbd0b116c20bf35aeeb87d511.RData

Binary file not shown.

0
README_cache/gfm/t2_733bbc8dbd0b116c20bf35aeeb87d511.rdb

BIN
README_cache/gfm/t2_733bbc8dbd0b116c20bf35aeeb87d511.rdx

Binary file not shown.

BIN
README_cache/gfm/t5_00c0c60f098627065befce9733d2db8a.RData

Binary file not shown.

0
README_cache/gfm/t5_00c0c60f098627065befce9733d2db8a.rdb

BIN
README_cache/gfm/t5_00c0c60f098627065befce9733d2db8a.rdx

Binary file not shown.

BIN
README_cache/gfm/unnamed-chunk-2_f358e3ab09a199cd320485fc64c5927a.RData

Binary file not shown.

BIN
README_cache/gfm/unnamed-chunk-2_f358e3ab09a199cd320485fc64c5927a.rdb

Binary file not shown.

BIN
README_cache/gfm/unnamed-chunk-2_f358e3ab09a199cd320485fc64c5927a.rdx

Binary file not shown.

BIN
README_cache/gfm/unnamed-chunk-3_9f255a7595eed3b772236e145ed48614.RData

Binary file not shown.

0
README_cache/gfm/unnamed-chunk-3_9f255a7595eed3b772236e145ed48614.rdb

BIN
README_cache/gfm/unnamed-chunk-3_9f255a7595eed3b772236e145ed48614.rdx

Binary file not shown.

BIN
README_cache/gfm/waffle-bars_885120d387eb4c3e265330249432d960.RData

Binary file not shown.

BIN
README_cache/gfm/waffle-bars_885120d387eb4c3e265330249432d960.rdb

Binary file not shown.

BIN
README_cache/gfm/waffle-bars_885120d387eb4c3e265330249432d960.rdx

Binary file not shown.

BIN
README_files/figure-gfm/unnamed-chunk-2-1.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

BIN
README_files/figure-gfm/unnamed-chunk-2-2.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

BIN
README_files/figure-gfm/unnamed-chunk-2-3.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

BIN
inst/fonts/fa-regular-400.ttf

Binary file not shown.

16
man/geom_waffle.Rd

@ -1,5 +1,5 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/sw2.R
% Please edit documentation in R/geom-waffle.R, R/stat-waffle.R
\docType{data}
\name{geom_waffle}
\alias{geom_waffle}
@ -10,13 +10,13 @@
\format{An object of class \code{GeomWaffle} (inherits from \code{GeomRtile}, \code{GeomRrect}, \code{Geom}, \code{ggproto}, \code{gg}) of length 5.}
\usage{
geom_waffle(mapping = NULL, data = NULL, n_rows = 10,
make_proportional = FALSE, na.rm = NA, show.legend = NA,
flip = FALSE, radius = grid::unit(0, "npc"), inherit.aes = TRUE,
...)
make_proportional = FALSE, flip = FALSE, na.rm = NA,
show.legend = NA, radius = grid::unit(0, "npc"),
inherit.aes = TRUE, ...)
GeomWaffle
stat_waffle(mapping = NULL, data = NULL, geom = "blank",
stat_waffle(mapping = NULL, data = NULL, geom = "waffle",
n_rows = 10, make_proportional = FALSE, flip = FALSE,
radius = grid::unit(0, "npc"), na.rm = NA, show.legend = NA,
inherit.aes = TRUE, ...)
@ -48,6 +48,9 @@ will be used as the layer data.}
\item{make_proportional}{compute proportions from the raw values? (i.e. each
value \code{n} will be replaced with \code{n}/\code{sum(n)}); default is \code{FALSE}.}
\item{flip}{If \code{TRUE}, flip x and y coords. n_rows then becomes n_cols.
Useful to achieve waffle column chart effect. Defaults is \code{FALSE}.}
\item{na.rm}{If \code{FALSE}, the default, missing values are removed with
a warning. If \code{TRUE}, missing values are silently removed.}
@ -57,9 +60,6 @@ a warning. If \code{TRUE}, missing values are silently removed.}
It can also be a named logical vector to finely select the aesthetics to
display.}
\item{flip}{If \code{TRUE}, flip x and y coords. n_rows then becomes n_cols.
Useful to achieve waffle column chart effect. Defaults is \code{FALSE}.}
\item{radius}{radius}
\item{inherit.aes}{If \code{FALSE}, overrides the default aesthetics,

2
waffle.Rproj

@ -19,4 +19,4 @@ PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageBuildArgs: --resave-data
PackageCheckArgs: --as-cran
PackageRoxygenize: rd,collate,namespace
PackageRoxygenize: rd,collate,namespace,vignette

Loading…
Cancel
Save