-
Notifications
You must be signed in to change notification settings - Fork 5
/
README.Rmd
93 lines (57 loc) · 3.05 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
---
title: "pier"
#author: "mrj"
#date: "10 May 2016"
output:
rmarkdown::github_document
---
[![DOI](https://zenodo.org/badge/56191948.svg)](https://zenodo.org/badge/latestdoi/56191948)
[![R-CMD-check](https://github.com/mrjoh3/pier/workflows/R-CMD-check/badge.svg)](https://github.com/mrjoh3/pier/actions)
[![codecov](https://codecov.io/gh/mrjoh3/pier/branch/master/graph/badge.svg)](https://codecov.io/gh/mrjoh3/pier)
The `pier` package (pronounced pie-r) is a wrapper, or [htmlwidget](http://www.htmlwidgets.org/), for the [d3pie](http://d3pie.org/) javascript library by [Benjamin Keen](https://github.com/benkeen). If you are just wanting to generate a pie chart the d3pie website has a fantastic [generator](http://d3pie.org/#generator) that will create the code that you need. If you are wanting create a chart using [R](https://www.r-project.org/) for embedding in a Rmarkdown document or Shiny App, then you are in the right place.
The `d3pie` library is very versatile and includes a lot of options. Currently this package only wraps the [configuration object](http://d3pie.org/#docs-configuration). Even with this current limitation a wide range of options are available.
Currently the intention is to wrap the entire [d3pie](http://d3pie.org/#docs-api) api.
## Installation
You probably already guesssed this bit.
```{r install, eval=FALSE}
devtools::install_github("mrjoh3/pier")
```
## Usage
The `pier` package is intended to be as simple and lightweight as possible. As a starting point the data input must be a `data.frame` with three required columns: `label`, `value` and `color`. From this point most of the defaults from `d3pie` are carried over. Note that all examples here have lost their interactivity.
```{r data, warning=FALSE, message=FALSE, fig.align='center', fig.width=8}
library(pier)
data <- data.frame(label = c('Environment','Education','Business','Community'),
value = c(104,119,638,1250),
color = RColorBrewer::brewer.pal(4, 'Spectral'))
simple.pie <- pier(data)
htmlwidgets::onRender(simple.pie, 'document.getElementsByTagName("svg")[0].setAttribute("viewBox", "")')
```
```{r p1, echo=FALSE, eval=FALSE, fig.align='center', fig.width=6, fig.height=4}
simple.pie %>%
pie.effects(load = list(effect = 'none',
speed = 2000)) %>%
pie.size(width = 600, height = 450)
```
<center>
<img src = "img/p1.png" />
</center>
|
## Advanced Usage
```{r advanced, fig.width=7, fig.align='center'}
advanced.pie <- data %>%
pier() %>%
pie.size(inner=70, outer=100, width = 600, height = 450) %>%
pie.header(text='Segments', font='Impact', location='pie-center') %>%
pie.subtitle(text='by Type') %>%
pie.footer(text='Economic Segments using fake data.',
location = 'bottom-left') %>%
pie.tooltips()
```
```{r p2, echo=FALSE, eval=FALSE, fig.align='center', fig.width=6, fig.height=4}
advanced.pie %>%
pie.effects(load = list(effect = 'default',
speed = 1000))
```
<center>
<img src = "img/p2.png" />
</center>