2017-08-17 9 views
2

私は同じ側に複数のy軸を持つプロットをRで作成しました。ただし、追加の軸がプロットをオーバーレイし、グラフのノイズが多いほど問題が発生します。複数の軸を持つプロット

これは私が持っているものです。私の知る限り

library(plotly) 
ay <- list(
    tickfont = list(color = "red"), 
    overlaying = "y", 
    side = "left", 
    title = "second y axis", 
    position = 0.1 
) 
p <- plot_ly() %>% 
    add_lines(x = ~1:3, y = ~10*(1:3), name = "slope of 10") %>% 
    add_lines(x = ~2:4, y = ~1:3, name = "slope of 1", yaxis = "y2") %>% 
    layout(
    title = "Double Y Axis", yaxis2 = ay, 
    xaxis = list(title="x") 
) 

p 

答えて

1

enter image description here

サンプルコード:私は必要なものながら

enter image description here

はこのようなものです、複数のy軸は対応していませんctlyはRのためにplotlyで管理されており、上記の問題を回避するために利用できる唯一の方法はmarginという属性を、hereのように調整することです。

library(plotly) 
ay <- list(
    tickfont = list(color = "red"), 
    overlaying = "y", 
    side = "left", 
    title = "second y axis", 
    anchor="free" 
) 

p <- plot_ly() %>% 
    add_lines(x = ~1:3, y = ~10*(1:3), name = "slope of 10") %>% 
    add_lines(x = ~2:4, y = ~1:3, name = "slope of 1", yaxis = "y2") %>% 
    layout(
    title = "Double Y Axis", yaxis2 = ay, 
    xaxis = list(title="x"), 
    yaxis = list(showline = FALSE, side="left"), 
    margin=list(pad = 50, b = 90, l = 150, r = 90) 
) 
p 

enter image description here

+0

ありがとうございます!これは私が2つのy軸を持っているときにはうまくいくが、もっと多く持っていればまだ2番目、3番目などが重ねてある。何か案は? –

関連する問題