Black Lives Matter. Please consider donating to Black Girls Code today.

Aggregations in R

How to use aggregates in R with Plotly.

Building AI apps or dashboards in R? Deploy them to Dash Enterprise for hyper-scalability and pixel-perfect aesthetic.
10% of the Fortune 500 uses Dash Enterprise to productionize AI & data science apps.
Find out if your company is using Dash Enterprise

Install Dash Enterprise on Azure | Install Dash Enterprise on AWS

New to Plotly?

Plotly is a free and open-source graphing library for R. We recommend you read our Getting Started guide for the latest installation or upgrade instructions, then move on to our Plotly Fundamentals tutorials or dive straight in to some Basic Charts tutorials.


Aggregates are a type of transform that can be applied to values in a given expression. Available aggregations are:

Function Description
count Returns the quantity of items for each group.
sum Returns the summation of all numeric values.
avg Returns the average of all numeric values.
median Returns the median of all numeric values.
mode Returns the mode of all numeric values.
rms Returns the rms of all numeric values.
stddev Returns the standard deviation of all numeric values.
min Returns the minimum numeric value for each group.
max Returns the maximum numeric value for each group.
first Returns the first numeric value for each group.
last Returns the last numeric value for each group.

Basic Example


fig <- plot_ly(
  type = 'scatter',
  x = diamonds$cut,
  y = diamonds$price,
  mode = 'markers',
  transforms = list(
      type = 'aggregate',
      groups = diamonds$cut,
      aggregations = list(
          target = 'y', func = 'sum', enabled = T