r - Plotly 中子图的标题

标签 r plotly

我正在尝试在 Plotly 中制作一个 3x3 子图的网格。我正在尝试获取每个子图的标题和顶部的主标题,但我似乎无法让它工作。
我看到这个 wonderful site对于 Python,但我似乎找不到 R 的等效项。

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。

任何人都可以提供帮助吗?

最佳答案

您可以使用 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

关于r - Plotly 中子图的标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45200544/

相关文章:

r - 查找两列中的重复项

r - 如何在R中更新软件包?

r - 如何在plotly中为3D绘图的轴标签添加上标或下标?

charts - 为什么这个 XPlot.Plotly 代码不能编译>

r - plotly 等值线图 : display country names

r - Plotly:使用 for 循环添加跟踪时,文本会被覆盖

r - 在绘图的空白处打印一个 data.frame

r - 是否可以将ggplot的标题向右对齐?

r - 使用 R 中 randomForest 包中的 rfimpute 时出现内存错误

python - 我正在用 plotly express 制作等值线图。如何将我的 csv 数据框中的值与 geojson 文件中的国家相匹配?