Skip to content

AdamSpannbauer/rPackedBar

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
 
 
man
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

rPackedBar

Travis-CI Build Status Coverage Status CRAN_Status_Badge

Packed Bar Charts in R with Plotly (Introducing Packed Bars)

This small package is an adaptation of the packed bar chart introduced by XanGregg in a JMP User Community Post (XanGregg's packed bar git repo). The package currently consists of only 1 function to make a packed bar chart using plotly.

Output

Usage

#install package from github
devtools::install_github("AdamSpannbauer/rPackedBar")

#use sample data from treemap package
data(GNI2014, package = 'treemap')
data.table::setDT(GNI2014)

#inspect raw data
head(GNI2014)
#    iso3          country     continent population    GNI
# 1:  BMU          Bermuda North America      67837 106140
# 2:  NOR           Norway        Europe    4676305 103630
# 3:  QAT            Qatar          Asia     833285  92200
# 4:  CHE      Switzerland        Europe    7604467  88120
# 5:  MAC Macao SAR, China          Asia     559846  76270
# 6:  LUX       Luxembourg        Europe     491775  75990

#summarize data to plot
my_input_data = GNI2014[,sum(population), by=country]
#inspect data to plot
head(my_input_data)
#             country      V1
# 1:          Bermuda   67837
# 2:           Norway 4676305
# 3:            Qatar  833285
# 4:      Switzerland 7604467
# 5: Macao SAR, China  559846
# 6:       Luxembourg  491775

#packed bar with default settings
plotly_packed_bar(my_input_data,
                  label_column = 'country',
                  value_column = 'V1')

#customized packed bar
plotly_packed_bar(my_input_data,
                  label_column    = 'country',
                  value_column    = 'V1',
                  number_rows     = 4,
                  plot_title      = 'Population 2014',
                  xaxis_label     = 'Population',
                  hover_label     = 'Population',
                  min_label_width = .025,
                  color_bar_color ='orange')