[英]Change y limits in subplot plotly
我正在使用 plotly 庫來繪制一系列共享公共 x 軸的圖形。 縮放子圖函數下的文檔中顯示了一個示例 - https://plotly.com/r/subplots/
有沒有辦法改變每個單獨地塊的 y 限制? 這是我的例子
library(plotly)
data <- data.frame("Time" = 1:100, "y1" = rnorm(100), "y2" = rnorm(100))
df <- data %>%
tidyr::gather(variable, value, -Time) %>%
transform(id = as.integer(factor(variable)))
df$variable <- factor( df$variable, levels = unique( df$variable))
p <- plot_ly(data = df,x = ~Time, y = ~value, color = ~variable, colors = "Dark2",
yaxis = ~paste0( "y",sort(id, decreasing = F))
) %>%
add_lines() %>%
plotly::subplot(nrows = length(unique(df$variable)), shareX = TRUE)
p
在上面的代碼中,如何將 y2 的 yaxis 限制從 -10 更改為 10?
您只需添加一個layout
-layer 並使用yaxis2
參數定義第二個繪圖的yaxis2
。
data <- data.frame("Time" = 1:100, "y1" = rnorm(100), "y2" = rnorm(100))
df <- data %>%
tidyr::gather(variable, value, -Time) %>%
transform(id = as.integer(factor(variable)))
df$variable <- factor( df$variable, levels = unique( df$variable))
p <- plot_ly(data = df,x = ~Time, y = ~value, color = ~variable, colors = "Dark2",
yaxis = ~paste0( "y",sort(id, decreasing = F))
) %>%
add_lines() %>%
plotly::subplot(nrows = length(unique(df$variable)), shareX = TRUE)
p %>%
layout(yaxis2 = list(range = c(-10,10)))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.