library(plotly)
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.3.2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
m <- economics[which.max(economics$unemploy), ]
n <- economics[which.max(economics$uempmed), ]
# font style
f <- list(
family = "Courier New, monospace",
size = 18,
color = "black")
# annotations
a <- list(
text = "SUBPLOT TITLE A",
font = f,
xref = "paper",
yref = "paper",
yanchor = "bottom",
xanchor = "center",
align = "center",
x = 0.5,
y = 1,
showarrow = FALSE
)
b <- list(
text = "SUBPLOT TITLE B",
font = f,
xref = "paper",
yref = "paper",
yanchor = "bottom",
xanchor = "center",
align = "center",
x = 0.5,
y = 1,
showarrow = FALSE
)
p1 <- plot_ly(economics, x = ~date, y = ~unemploy) %>%
add_lines(name = ~"unemploy") %>%
layout(annotations = a)
p2 <- plot_ly(economics, x = ~date, y = ~uempmed) %>%
add_lines(name = ~"uempmed") %>%
layout(annotations = b)
p <- subplot(p1, p2, titleX = TRUE, titleY = TRUE) %>%
layout(showlegend = FALSE)
p
See https://plot.ly/r/reference/#layout-annotations for more information and chart attribute options!