2016-05-17 12 views
7

geben Ich frage mich, wie man Untertitel für die Unterplots mit Plot_ly geben. Irgendein Hinweis bitte. Ich habe in diesem Fall einen Titel BB. Vielen Dank.Wie Untertitel für Teilplot in Plot_ly mit R

p <- subplot(
     plot_ly(economics, x = date, y = uempmed)%>%layout(showlegend = FALSE, title="AA"), 
     plot_ly(economics, x = date, y = unemploy)%>%layout(showlegend = FALSE, title="BB"), 
margin = 0.05 
) 

Antwort

9

Das title Attribut in dem Layout bezieht sich auf den Titel für die gesamte Plotfläche, so kann es nur einen geben. Wir können jedoch Textanmerkungen verwenden, um "Titel" für Ihre Unterplots zu erstellen, zum Beispiel:

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')) 
)