rspivot: Additional Features

Graphical view

The plot tab provides the option to view the table as a chart. This can be displayed as a line chart, grouped bars, or stacked bars.

Columns in the pivot table are used as the x-axis, while the selected rows are each represented as a data group. If the pivot table has nested rows, each of those nests is separated into facets.

This feature is in development.

Data options

The data table options tab provides options for summarizing and modifying the values shown in the pivot table. From left to right, the options listed follow the same flow as the calculations to display the data table.

Pivot table values

Pivot table values determine what is shown in the data tables. This tells the pivot tables how to combine every value in the data frame that belongs to a particular row and column.

If you are familiar with the dplyr package, these are the functions that are passed to dplyr::summarize(). Any function that summarizes groups of data into a single value can be used. Most common ones are provided as defaults in the menu.

The pivot table value function can be set on the initial function call using the initPivotValues input.

rspivot(GVAIndustry, initPivotValues = "mean")


The default pivot table value is sum(., na.rm=TRUE). Every data point that belongs to a particular row and column will be added together, ignoring NA values.

Mean, Median, Min, Max

The pivot table values menu contains a selection of default functions that can be used to summarize the data frame. The options for mean, median, min, and max all default to na.rm=TRUE.


The count option provides a count of the number of data values that contribute to each row and column. This uses the functiondplyr::n().

Custom functions

In addition to the defaults, any single input named function that summarizes data groups and returns a single value can be passed to the rspivot() function call. This function will be added to the list of options in the Pivot Table Values menu for toggling during the session. Wrapping the name of the function in c() allows you to provide a human-readable name for the function.

sd_narm <- function(x){
  return(sd(x, na.rm=TRUE))

rspivot(GVAIndustry, initPivotValues = c("StDev" = "sd_narm"))

Data modes

Data modes are applied to the pivot table after the values are calculated. The default is to display the values unaltered.

Data modes are valuable for reviewing data, as the data can be viewed as differences, % growth rates, or % shares of the total. If any of these alternate modes are selected, another select menu appears with a list of each of the series in the data frame. This determines over which series the metrics are calculated.

For example, rspivot(GVAIndustry, initRows = "Country", initMetric = list(metric = "Shares", series = "Country")) will transform the data into country shares, where the sum of all countries will equal 100%, while rspivot(GVAIndustry, initRows = "Industry", initMetric = list(metric = "Shares", series = "Industry")) will ensure the sum of all industries will equal 100%.

It is recommended that the Data Mode series is viewed as a row or column in the pivot table.

When viewing the data values as a mode, set the Nested Rows series to *Metric* to view both the values and the data mode at the same time. This option can be set at the rspivot() function call as well with initNest = "Metric_calc".

rspivot(GVAIndustry, initCols = "Year", initRows = "Industry", initNest = "Metric_calc",                         initMetric = list(metric = "Growth", series = "Year"))

Other options

Decimal digits

For each the data values and the data metric values, specify the number of digit to include in each value.


View data as thousands, millions, or billions.

Truncate strings

For long strings, limit the number of displayed characters. The default value is 30. This does not affect the strings in the filter and row/column menus.