Title of Subplots in Plotly

爱⌒轻易说出口 提交于 2019-12-14 01:28:06

问题


I am trying to make a grid of 3x3 subplots in Plotly. I'm trying to get titles for each subplot and a main title on the top and I can't seem to get it to work. I see this wonderful site for Python but I can't seem to find its equivalent for R.

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

That gave me the grid I wanted but don't have the titles I want on the subplots:

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

and the the default Main Title was Graph 9.

Can anyone assist?


回答1:


You could use ggplot + plotly to achieve it. This does the trick:

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



来源:https://stackoverflow.com/questions/45200544/title-of-subplots-in-plotly

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!