[英]R plotly frame with multiple x-axis
我正在尝试使用 plotly 绘制线图,如下所示:
library(plotly)
library(dplyr)
datatoplot<-structure(list(year = c(1397, 1397, 1397, 1397, 1397, 1397, 1397,
1397, 1397, 1397, 1397, 1397, 1398, 1398, 1398, 1398, 1398, 1398,
1398, 1398, 1398, 1398, 1398, 1398, 1399, 1399, 1399, 1399, 1399,
1399, 1399, 1399, 1399, 1399, 1399, 1399), month = c(1, 2, 3,
4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), v10 = c(2.8,
5.1, 6.3, 4.8, 4.1, 2.9, 3, 3.6, 4.4, 4.1, 3.4, 5.9, 1.7, 2.5,
2.1, 2.7, 2.3, 3, 3.2, 3.6, 2, 2, 1.6, 2.6, 1.5, 4, 2.9, 3.6,
3.6, 2.5, 2.2, 1.6, 1.9, 2.2, 3.6, 4.5), v14 = c(0.67, 0.65,
0.56, 0.65, 0.73, 0.67, 0.6, 0.64, 0.61, 0.61, 0.69, 0.64, 0.69,
0.75, 0.76, 0.73, 0.76, 0.68, 0.73, 0.92, 0.69, 0.66, 0.78, 0.71,
0.67, 0.68, 0.69, 0.73, 0.68, 0.76, 0.73, 0.81, 0.75, 0.8, 0.8,
0.71)), row.names = c(NA, 36L), class = "data.frame")
datatoplot %>% plot_ly( alpha = 0.5) %>%
add_lines(
x = ~list(year,month), y = ~v10
#,frame=~list(year,month)
,line = list(simplify = FALSE)
) %>%
layout(yaxis = list(title = "A"))
输出如下:
现在我想使用 'frame' 参数将一个框架添加到绘图中
frame=~list(year,month)
但不幸的是它不起作用,输出如下:
不确定这是否是您的预期输出,但在我看来,将year
设置为frame
有意义的:
library(plotly)
library(dplyr)
datatoplot <- structure(
list(
year = c(1397, 1397, 1397, 1397, 1397, 1397, 1397, 1397, 1397, 1397,
1397, 1397, 1398, 1398, 1398, 1398, 1398, 1398, 1398, 1398, 1398, 1398,
1398, 1398, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399,
1399, 1399),
month = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8,
9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12),
v10 = c(2.8, 5.1, 6.3, 4.8, 4.1, 2.9, 3, 3.6, 4.4, 4.1, 3.4, 5.9, 1.7,
2.5, 2.1, 2.7, 2.3, 3, 3.2, 3.6, 2, 2, 1.6, 2.6, 1.5, 4, 2.9, 3.6, 3.6,
2.5, 2.2, 1.6, 1.9, 2.2, 3.6, 4.5),
v14 = c(0.67, 0.65, 0.56, 0.65, 0.73, 0.67, 0.6, 0.64, 0.61, 0.61, 0.69,
0.64, 0.69, 0.75, 0.76, 0.73, 0.76, 0.68, 0.73, 0.92, 0.69, 0.66, 0.78,
0.71, 0.67, 0.68, 0.69, 0.73, 0.68, 0.76, 0.73, 0.81, 0.75, 0.8, 0.8,
0.71)
),
row.names = c(NA, 36L),
class = "data.frame"
)
datatoplot %>% plot_ly(alpha = 0.5) %>%
add_lines(
x = ~ month,
y = ~ v10,
frame = ~ year,
line = list(simplify = FALSE)
) %>%
layout(yaxis = list(title = "A"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.