r - R 中的子图与 Plotly
问题描述
我试图了解 Plotly 中的子图功能是如何工作的。
我有以下两个例子:
library(plotly)
## Create a data frame with data to be plotted
S <- seq(1,100)
DF <- data.frame(S = S, A = S, B = sin(S), C = S^2, D = 1/S, E = S^3 + S^3*cos(S))
## Create first plot, 'P_A' with trace 'A'
DF %>%
plot_ly() %>%
add_lines(x = ~S , y = ~ A, yaxis = "y", name = "A",color = I("red")) %>%
layout(yaxis = list(side = "left", title = "Axis A")) -> P_A
## Create second plot, 'P_BC', with traces 'B' and 'C'
DF %>%
plot_ly() %>%
add_lines(x = ~S , y = ~ B, yaxis = "y", name = "B", color = I("blue")) %>%
add_lines(x = ~S , y = ~ C, yaxis = "y2", name = "C", color = I("green")) %>%
layout(yaxis = list(side = "left", title = "Axis B"),
yaxis2 = list(side = "right", title = "Axis C", overlaying = "y2")) -> P_BC
## Create third plot, 'P_DE', with traces 'D' and 'E'
DF %>%
plot_ly() %>%
add_lines(x = ~S , y = ~ D, yaxis = "y", name = "D", color = I("orange")) %>%
add_lines(x = ~S , y = ~ E, yaxis = "y4", name = "E", color = I("purple")) %>%
layout(yaxis = list(side = "left", title = "Axis D"),
yaxis4 = list(side = "right", title = "Axis E", overlaying = "y4")) -> P_DE
## Create a subplot
subplot(list(P_A,P_BC,P_DE),nrows = 2)
subplot(list(P_BC,P_DE),nrows = 2)
我不明白为什么在第二个子图中,排除 P_A 图会导致其他轨迹不显示。
谢谢你,马可
解决方案
推荐阅读
- android - 具有旧值的 SensorEvent
- javascript - Select2 在 foreach 循环中不起作用并保持其原始宽度
- c# - EasyModbus TCP 通信减慢 Windows 应用程序
- php - PHP 更改 JSON 格式
- watchkit - 用自定义颜色填充 RoundedRectangle
- scenekit - 从 didAdd 锚点获取 ARAnchor 的旋转
- java - Lotus Notes Java API 编码错误
- r - 比较 ARIMA 和 GARCH 模型的 AIC
- javascript - Angular Material:如何在 mat-table 中选择特定的 mat-cell?
- java - 使用不同语言环境的 DecimalFormat 错误地解析字符串