2

これに似たRでプロットを作成しようとしています: ここに画像の説明を入力

最大 6 つの変数を使用でき、リアクティブである必要があります。

私はplotlyを試しましたが、plotlyではプロットに軸の目盛りが表示され、乱雑になり、y軸を1つだけ取り出すことができました。

ここに画像の説明を入力

plotly または他の対話型ライブラリでプロットを再作成する方法はありますか?

私の陰謀的なコード:

library(dplyr)
library(plotly)
library(tidyr)

data <- cbind(
  seq(from = 1, to = 30, by = 1),
  sample(seq(from = 100, to = 300, by = 10), size = 30, replace = TRUE),
  sample(seq(from = 1, to = 100, by = 9), size = 30, replace = TRUE),
  sample(seq(from = 50, to = 60, by = 2), size = 30, replace = TRUE),
  sample(seq(from = 100, to = 130, by = 1), size = 30, replace = TRUE)
) %>% 
  as.data.frame()

names(data) <- c("date", "a", "b", "x", "y")

plot_ly(x = ~data$date) %>%
  add_lines(y = ~data[, 2], name = "a", line = list(color = "red")) %>%
  add_lines(y = ~data[, 3], name = "b", line = list(color = "blue"), yaxis = "y2") %>%
  add_lines(y = ~data[, 4], name = "x", line = list(color = "green"), yaxis = "y3") %>%
  add_lines(y = ~data[, 5], name = "y", line = list(color = "pink"), yaxis = "y4") %>%
  layout(
    yaxis = list(
      side = "left",
      title = list("")
    ),
    yaxis2 = list(
      side = "left",
      overlaying = "y",
      anchor = "free"
    ),
    yaxis3 = list(
      side = "left",
      overlaying = "y",
      anchor = "free",
      position = 0.04
    ),
    yaxis4 = list(
      side = "left",
      overlaying = "y",
      anchor = "free",
      position = 0.08
    ),
    margin = list(pad = 30)
  )
4

3 に答える 3