Skip to content

mrjoh3/pier

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
R
 
 
img
 
 
 
 
man
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

pier

DOI R-CMD-check codecov

The pier package (pronounced pie-r) is a wrapper, or htmlwidget, for the d3pie javascript library by Benjamin Keen. If you are just wanting to generate a pie chart the d3pie website has a fantastic generator that will create the code that you need. If you are wanting create a chart using R 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. Even with this current limitation a wide range of options are available.

Currently the intention is to wrap the entire d3pie api.

Installation

You probably already guesssed this bit.

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.

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", "")')

Advanced Usage

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()