How to give subtitles for subplot in plot_ly using R

The title attribute in layout refers to the title for the entire plotting surface, so there can only be one. However, we can use text annotations to create "titles" for your subplots, for example:

p <- subplot(
  plot_ly(economics, x = date, y = uempmed)%>%layout(showlegend = FALSE),
  plot_ly(economics, x = date, y = unemploy)%>%layout(showlegend = FALSE),
  margin = 0.05
) 
p %>% layout(annotations = list(
 list(x = 0.2 , y = 1.05, text = "AA", showarrow = F, xref='paper', yref='paper'),
  list(x = 0.8 , y = 1.05, text = "BB", showarrow = F, xref='paper', yref='paper'))
)

Instead of positioning "by hand" (i.e., @d-roy's answer), you can now leverage subplot()'s ability to reposition paper referenced things like annotations (as well as shapes, images, etc).

library(plotly)
library(dplyr)

my_plot <- . %>% 
  plot_ly(x = ~date, y = ~value) %>%
  add_annotations(
    text = ~unique(variable),
    x = 0.5,
    y = 1,
    yref = "paper",
    xref = "paper",
    xanchor = "middle",
    yanchor = "top",
    showarrow = FALSE,
    font = list(size = 15)
  )

economics_long %>%
  group_by(variable) %>%
  do(p = my_plot(.)) %>%
  subplot(nrows = NROW(.), shareX = TRUE)