r - 公共(public)轴子图与 plot.ly for R

标签 r plotly

我正在尝试将子图与 plot.ly R 库一起用于交互式在线图表。我可以成功地创建一个子图,但是我很难只拥有两个图表共有的单个 y 轴。

plot.ly 网站确实提供了一个常见 x 轴的示例,但是使用和附加 trace 而不是 group plot_ly() 函数中提供的选项。

示例代码:

library(data.table)
library(plotly)
dt <- data.table(x = c("A","B","C","D","A","B","C","D"),
                 y = c(12,4,3,9,5,10,3,7),
                 group = factor(c(rep("G1",4),rep("G2",4))))
dt$id <- as.integer(dt$group)
xx <- xaxis_standard
yy <- yaxis_standard
p <- plot_ly(dt, x=x, y=y, group = group, xaxis = paste0("x",id)) 
p <- layout(p, yaxis = list(range = c(0, max(y))))
p <- subplot(p, margin = 0.05) 
p <- layout(p,showlegend = F, yaxis = list(anchor = 'x1'))
p

这张图片显示了我执行代码时的结果。 Plot.ly subplot chart

我想要的是同一张图表,但右侧子图中没有 y 轴。

最佳答案

子图位于标记为 xaxis2yaxis2 等的单独轴上。这些轴也是 layout() 的参数。

p <- layout(p, showlegend = F, yaxis = list(anchor = 'x1'), 
            yaxis2 = list(showticklabels = F))
p

enter image description here

关于r - 公共(public)轴子图与 plot.ly for R,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39325656/

相关文章:

r - 简单的 R 函数问题

arrays - R 数组分配中的内存使用情况

r - 基于 Y 值的 R Plotly 中的多色线图

r - 在 R Plotly 中命名 3D 曲面图的图例

python - 等值线世界地图未显示所有国家

html - Rmarkdown : embed html file to ioslides

r - 如何翻译引用文献/引用书目部分的标题?

c - 从 R 调用这个 C 函数(libqp_gsmo.c)的方法是什么?

r - 我可以将 "OBJ"网格文件映射到现有 R 包吗?

Plotly.js 等值线 map 大小