项目作者: liamgilbey

项目描述 :
Creating waffle charts in a ggplot friendly way
高级语言: R
项目地址: git://github.com/liamgilbey/ggwaffle.git
创建时间: 2018-08-24T08:48:58Z
项目社区:https://github.com/liamgilbey/ggwaffle

开源协议:GNU General Public License v2.0

下载


" class="reference-link">ggwaffle

Travis Build
Status
Codecov test
coverage

Create waffle charts in R in a ggplot2-friendly way.

Acknowledgements

Really all credit to Bob Rudis for the
work done on the original waffle
package
.

Description

ggwaffle is designed to work in a very similar way to the original
waffle package, while being
slightly closer to the workflow of a standard ggplot graphic.
Consequently, it is a little more verbose.

Installation

Currently only available through github:

  1. # install.packages("devtools")
  2. devtools::install_github("liamgilbey/ggwaffle")

Usage

ggwaffle heavily relies on the usage of
ggplot2. Much like standard
ggplot graphs, waffle charts are created by adding layers to a base
graphic. Because of the inner mechanisms of ggplot2, some of the
necessary data transformations have to be completed outside of a
standard plot creation. The function waffle_iron has been added to
help with issue.

ggwaffle also introduces a column mapping function, aes_d. At this
stage I have no idea of how useful this is outside the context of the
package, but it seemed a nice way to specify dynamic column renaming.
aes_d is obviously coined from ggplot’s aes function and has a very
similar idea. Here we are mapping column names to feed into a function
so they can be renamed for used appropriately.

  1. library(ggwaffle)
  2. #> Loading required package: ggplot2
  3. waffle_data <- waffle_iron(mpg, aes_d(group = class))
  4. ggplot(waffle_data, aes(x, y, fill = group)) +
  5. geom_waffle()

Functions have also been included to make the default graphics more
waffle-like. theme_waffle is a ggplot theme that strips back a lot of
the elements of the waffle to create a cleaner look. scale_fill_waffle
returns a discrete scale to make your charts look a lot like waffles.
Using coord_equal is recommended to make the size of the blocks even
in all dimensions.

  1. waffle_data <- waffle_iron(iris, aes_d(group = Species))
  2. ggplot(waffle_data, aes(x, y, fill = group)) +
  3. geom_waffle() +
  4. coord_equal() +
  5. scale_fill_waffle() +
  6. theme_waffle()

The shape of the waffle tile can also be controlled, choosing from
either a regular square, or a circle tile shape.

  1. waffle_data <- waffle_iron(iris, aes_d(group = Species))
  2. ggplot(waffle_data, aes(x, y, colour = group)) +
  3. geom_waffle(tile_shape = 'circle', size = 12) +
  4. coord_equal() +
  5. scale_colour_waffle() +
  6. theme_waffle()

Icons

The best way to implement icons into waffle charts is to use Guangchuang
YU’s
emojifont
package.

  1. library(emojifont)
  2. waffle_data <- waffle_iron(iris, aes_d(group = Species))
  3. waffle_data$label = fontawesome('fa-twitter')
  4. ggplot(waffle_data, aes(x, y, colour = group)) +
  5. geom_text(aes(label=label), family='fontawesome-webfont', size=12) +
  6. coord_equal() +
  7. scale_colour_waffle() +
  8. theme_waffle()