2017-07-19 79 views
1

我想在Plotly中製作3x3子圖的網格。我試圖爲每個副歌和頂部的主要標題獲得標題,但似乎無法使其起作用。 我看到這個wonderful site爲Python,但我似乎無法找到它的等效R.Plotly中的子圖的標題

all <- subplot(graph1, graph2, graph3, graph4, graph5, graph6, 
graph7, graph8, graph9, nrows = 3) 

這給了我想要的電網,但沒有我想的次要情節的標題:

1. Graph 1 
2. Graph 2 
3. Graph 3 
4. Graph 4 
5. Graph 5 
6. Graph 6 
7. Graph 7 
8. Graph 8 
9. Graph 9 

和默認主標題是圖9.

任何人都可以協助嗎?

回答

1

你可以使用ggplot + plotly來實現它。這確實的伎倆:

library(ggplot2) 
library(plotly) 

mtcars$main1 = "title1" 
mtcars$main2 = "title2" 

p1 = ggplot(mtcars, aes(x = mpg, y = cyl)) + geom_point() + facet_wrap(~main1) 
p2 = ggplot(mtcars, aes(x = disp, y = hp)) + geom_point() + facet_wrap(~main2) 

plotly::subplot(p1, p2 ,nrows = 1, margin = 0.23) %>% layout(title ="Main title") 

enter image description here