Customizing your layout

Interactive Data Visualization with plotly in R

Adam Loy

Statistician, Carleton College

layout()

  • axes: type, labels, tick marks, transformations, etc.
  • legend: position
  • canvas: grid lines, background color
  • size: height, width, margins
Interactive Data Visualization with plotly in R

Axis labels

winequality %>%
  plot_ly(x = ~free_so2, y = ~total_so2) %>%
  add_markers(marker = list(opacity = 0.2)) 
Interactive Data Visualization with plotly in R

Axis labels

winequality %>%
  plot_ly(x = ~free_so2, y = ~total_so2) %>%
  add_markers(marker = list(opacity = 0.2)) %>%
  layout(xaxis = list(title = "Free SO2 (ppm)"),
         yaxis = list(title = "Total SO2 (ppm)"))
Interactive Data Visualization with plotly in R

Titles

winequality %>%
  plot_ly(x = ~free_so2, y = ~total_so2) %>%
  add_markers(marker = list(opacity = 0.2)) %>%
  layout(xaxis = list(title = "Free SO2 (ppm)"),
         yaxis = list(title = "Total SO2 (ppm)"),
         title = "Does free SO2 predict total SO2 in wine?")
Interactive Data Visualization with plotly in R

Transforming axes

winequality %>%
  plot_ly(x = ~free_so2, y = ~total_so2) %>%
  add_markers(marker = list(opacity = 0.2)) %>%
  layout(xaxis = list(title = "Free SO2 (ppm, log scale)", type = "log"),
         yaxis = list(title = "Total SO2 (ppm, log scale)", type = "log"),
         title = "Does free SO2 predict total SO2 in wine?")
Interactive Data Visualization with plotly in R

Customizing the grid

Interactive Data Visualization with plotly in R

Customizing the grid

winequality %>%
  plot_ly(x = ~free_so2, y = ~total_so2) %>%
  add_markers(marker = list(opacity = 0.5)) %>%
  layout(xaxis = list(title = "Free SO2 (ppm)", zeroline = FALSE),
         yaxis = list(title = "Total SO2 (ppm)", zeroline = FALSE, 
                      showgrid = FALSE))
Interactive Data Visualization with plotly in R

Customizing the canvas

24_bgcolor.png

winequality %>%
  plot_ly(x = ~free_so2, y = ~total_so2) %>%
  add_markers(marker = list(opacity = 0.5)) %>%
  layout(xaxis = list(title = "Free SO2 (ppm)"),
         yaxis = list(title = "Total SO2 (ppm)"),
         plot_bgcolor = toRGB("gray90"),

paper_bgcolor = toRGB("skyblue"))
Interactive Data Visualization with plotly in R

Let's practice!

Interactive Data Visualization with plotly in R

Preparing Video For Download...