Это возможное решение с использованием annotations
:
library(plotly)
tab2 <- read.table(text="
trajet n prop
1 21654 0.15
2 3373 0.02
3 4443 0.03
4 20151 0.14
5 73990 0.53
9 16352 0.12
", header=T)
tab3 <- read.table(text="
trajet n prop
1 17743 0.19
2 2886 0.03
3 3341 0.04
4 12911 0.14
5 47726 0.52
9 7171 0.08
", header=T)
subtitle1 <- list(
x = 0.5-0.025, y = 0.5,
text = "Title 1",
xref = "paper", yref = "paper",
font=list(size=50),
xanchor="center", yanchor="center",
showarrow = FALSE
)
p1 <- plot_ly(tab2,
labels = ~c("Domicile-Travail","Domicile-ecole","Courses-achats",
"Utilisation professionnelle","Promenade-loisirs","Autre"),
values = ~prop, type = 'pie',
textposition = 'middle right',
textinfo = 'percent',
hole= "0.5",
domain = list(x = c(0, 0.45), y = c(0, 1)),
insidetextfont = list(color = '#FFFFFF'),
hoverinfo = 'text') %>%
layout(annotations = subtitle1)
subtitle2 <- list(
x = 0.5+0.025, y = 0.5,
text = "Title 2",
xref = "paper", yref = "paper",
font=list(size=50),
xanchor="center", yanchor="center",
showarrow = FALSE
)
p2 <- plot_ly(tab3,
labels= ~c("Domicile-Travail","Domicile-ecole","Courses-achats",
"Utilisation professionnelle","Promenade-loisirs","Autre"),
values = ~prop,
type = 'pie',
textposition = 'middle left',
textinfo = 'percent',
hole= "0.5",
domain = list(x = c(0.55,1), y = c(0, 1)),
insidetextfont = list(color = '#FFFFFF'),
hoverinfo = 'text') %>%
layout(annotations = subtitle2)
subplot(p1,p2)%>%
layout(title = "Nombre d'accidents par type de trajet",
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))