2016-07-25 7 views
0

Ich möchte mit 2 Achsen Mehr Plots auf jeder Parzelle zu tun, wie dieseplotly mehrere Grundstück Facette

library(plotly) 
ay <- list(
    tickfont = list(color = "green"), 
    overlaying = "y", 
    side = "right", title = "y2 axis title" 
) 


par(mfrow=c(2,1)) 
ax <-list(title = "x axis title") 
ay1 <-list(title = "y1 axds title") 
plot_ly(x = 1:3, y = 10*(1:3), name = "slope of 10") %>% 
    add_trace(x = 2:4, y = 1:3, name = "slope of 1", yaxis = "y2") %>% 
    layout(title = "Double Y Axis", yaxis2 = ay, xaxis = ax, yaxis = ay1) 


ax <-list(title = "x axis title") 
ay1 <-list(title = "y1 axds title") 
plot_ly(x = 1:3, y = 10*(1:3), name = "slope of 10") %>% 
    add_trace(x = 2:4, y = 1:3, name = "slope of 1", yaxis = "y2") %>% 
    layout(title = "Double Y Axis", yaxis2 = ay, xaxis = ax, yaxis = ay1) 

aber, wenn Sie diesen Code ausführen nur Sie noch ein Grundstück sehen. Kann Multiplots plotly machen? Kann es mit 2 Achsen facettieren?

+0

Versuchen Sie, diese 2 (gleiche) Plots auf der gleichen Seite zu zeichnen? – Sumedh

+0

ja. Ich möchte, dass sie sich übereinander zeigen. Aber im Idealfall möchte ich facet_wrap mit plotly verwenden können. ist das möglich? – user3022875

Antwort

0

Sie suchen nach subplot. Prüfen Sie dies page für mehr

library(plotly) 
ay <- list(
    tickfont = list(color = "green"), 
    overlaying = "y", 
    side = "right", title = "y2 axis title" 
) 

ax <-list(title = "x axis title") 
ay1 <-list(title = "y1 axds title") 

subplot(
     plot_ly(x = 1:3, y = 10*(1:3), name = "slope of 10") %>% 
      add_trace(x = 2:4, y = 1:3, name = "slope of 1", yaxis = "y2") %>% 
      layout(title = "Double Y Axis", yaxis2 = ay, xaxis = ax, yaxis = ay1), 
     plot_ly(x = 1:3, y = 10*(1:3), name = "slope of 10") %>% 
      add_trace(x = 2:4, y = 1:3, name = "slope of 1", yaxis = "y2") %>% 
      layout(title = "Double Y Axis", yaxis2 = ay, xaxis = ax, yaxis = ay1), nrows = 2) 

Ausgabe

enter image description here

+0

Wenn ich den obigen Code ausführen, wird das Diagramm nicht angezeigt. Ich entfernte auch das ")" nach "ay1" in der letzten Zeile – user3022875

+0

Ich postete die Ausgabe, die ich bekomme, wenn ich den genau gleichen Code ausführe. Ich benutze 'plotly_3.6.0' und' ggplot2_2.1.0' – Sumedh

+0

Versuchen Sie dies: Weisen Sie Ihre erste Grafik 'plot_ly' zu' a' und die zweite zu 'b' zu. Dann führe 'subplot (a, b, nrow = 2)' aus. Wird die Handlung jetzt angezeigt? – Sumedh

Verwandte Themen