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

R Figure Reference


The pages linked in the sidebar together form the exhaustive reference for all of the attributes in the core figure data structure that the plotly library operates on. They are automatically-generated from the machine-readable Plotly.js schema reference.

How are Plotly attributes organized?

plotly charts are described declaratively in the call signature of plotly::plot_ly, plotly::add_trace, and plotly::layout. Every aspect of a plotly chart (the colors, the grid-lines, the data, and so on) has a corresponding key in these call signatures. This page contains an extensive list of these attributes.

Plotly's graph description places attributes into two categories: traces (which describe a single series of data in a graph) and layout attributes that apply to the rest of the chart, like the title, xaxis, or annotations).

Here is a simple example of a plotly chart inlined with links to each attribute's reference section.

library(plotly)

    p <- plot_ly(economics,
                 type = "scatter",        # all "scatter" attributes: https://plotly.com/r/reference/#scatter
                 x = ~date,               # more about scatter's "x": /r/reference/#scatter-x
                 y = ~uempmed,            # more about scatter's "y": /r/reference/#scatter-y
                 name = "unemployment",   # more about scatter's "name": /r/reference/#scatter-name
                 marker = list(           # marker is a named list, valid keys: /r/reference/#scatter-marker
                   color="#264E86"        # more about marker's "color" attribute: /r/reference/#scatter-marker-color
                 )) %>%

      add_trace(x = ~date,                                         # scatter's "x": /r/reference/#scatter-x
                y = ~fitted((loess(uempmed ~ as.numeric(date)))),  # scatter's "y": /r/reference/#scatter-y
                mode = 'lines',                                    # scatter's "y": /r/reference/#scatter-mode
                line = list(                                       # line is a named list, valid keys: /r/reference/#scatter-line
                  color = "#5E88FC",                               # line's "color": /r/reference/#scatter-line-color
                  dash = "dashed"                                  # line's "dash" property: /r/reference/#scatter-line-dash
                )
      ) %>%

      layout(                        # all of layout's properties: /r/reference/#layout
             title = "Unemployment", # layout's title: /r/reference/#layout-title
             xaxis = list(           # layout's xaxis is a named list. List of valid keys: /r/reference/#layout-xaxis
                title = "Time",      # xaxis's title: /r/reference/#layout-xaxis-title
                showgrid = F),       # xaxis's showgrid: /r/reference/#layout-xaxis-showgrid
             yaxis = list(           # layout's yaxis is a named list. List of valid keys: /r/reference/#layout-yaxis
                title = "uidx")     # yaxis's title: /r/reference/#layout-yaxis-title
      )