Skip to content
Go to file


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.


You probably already guesssed this bit.



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.


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') %>%