plotly / plotly/plotly.R

Layout displays blank or axis overlap using dual axis graphs

Offen
#2,075 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
R
Sterne
2.7k
Forks
641
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

I have two dual yaxis plots that I'm trying to combine with plotly's layout function. Both plots work fine independently, but when combined some aspects are blank and the axis of the two graphs are combined on one graph. What do I need to do to get them to display properly, one on top of the other.

#my data
times.winter<- data.frame(radtime = c(0.0,0.26,0.52,0.78,1.05,1.31,1.57,1.83,2.09,2.36,2.62,2.88,3.14,3.4,3.66,3.93,4.19,4.45,4.71,4.97,5.23,5.50,5.76,6.02), 
mean.Ts2 = c(11.2,11.0,10.8,10.7,10.5,10.4,10.3,10.4,10.5,10.7,11.0,11.3,11.6,11.9,12.1,12.1,12.2,12.3,12.3,12.3,12.1,12.0,11.8,11.7,11.5), 
activity = c(1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10,1,2,3,4), 
time = c(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23))

times.summer<- data.frame(radtime = c(0.0,0.26,0.52,0.78,1.05,1.31,1.57,1.83,2.09,2.36,2.62,2.88,3.14,3.4,3.66,3.93,4.19,4.45,4.71,4.97,5.23,5.50,5.76,6.02), 
mean.Ts2 = c(17.1,16.9,16.7,16.6,16.4,16.3,16.3,16.3,16.4,16.6,16.8,17.1,17.3,17.5,17.7,17.8,17.8,17.8,17.7,17.6,17.5,17.4,17.3,17.1), 
activity = c(1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10,1,2,3,4), 
time = c(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23))

library(plotly)
Fig1<-plot_ly(times.winter) %>%
  add_bars(x = ~Time, y = ~activity, type = "bar", 
           marker = list(color = c("#999999","#999999","#999999","#999999","#999999","#999999",
                         "#999999","#999999","#999999","#999999","#999999","#999999",
                         "#999999","#999999","#4b0092","#999999","#999999","#999999",
                         "#999999","#999999","#999999","#999999","#999999","#999999"))) %>%
  add_lines(x = ~Time, y = ~mean.Ts2, yaxis = "y2", line = list(color = c("#E69F00"), width = 6)) %>%
  layout(xaxis = list(title = "Time",tick0 =0, dtick = 6),
         yaxis = list(showline = TRUE, side = "left", 
                      title = "Number Active",
                      showgrid = F),  
         yaxis2 = list(showline = TRUE,
                       tickfont = list(color = "#E69F00"),
                       dtick=0.5,
                       overlaying = "y",
                       side = "right",
                       title = "Soil Temperature °C",
                       color = "#E69F00",
                       range = list(10,13),
                       showgrid = F), 
         showlegend = FALSE,  
         margin = list(pad = 0, b = 50, l = 50, r = 50))

Fig2<-plot_ly(times.summer) %>%
  add_bars(x = ~Time, y = ~activity, type = "bar", 
           marker = list(color = c("#999999","#999999","#999999","#999999","#999999","#999999","#999999",
                                   "#999999","#999999","#999999","#999999","#4b0092","#999999",
                                   "#999999","#999999","#999999","#999999","#999999","#999999",
                                   "#999999","#999999","#999999","#999999","#999999"))) %>%
  add_lines(x = ~Time, y = ~mean.Ts2, yaxis = "y2", line = list(color = c("#E69F00"), width = 6)) %>%
  layout(xaxis = list(title = "Time",tick0 =0, dtick = 6),
         yaxis = list(showline = TRUE, side = "left", 
                      title = "Number Active",
                      showgrid = F),  
         yaxis2 = list(showline = TRUE,
                       tickfont = list(color = "#E69F00"),
                       dtick=0.5,
                       overlaying = "y",
                       side = "right",
                       title = "Soil Temperature °C",
                       color = "#E69F00",
                       range = list(16,18),
                       showgrid = F), 
         showlegend = FALSE,  
         margin = list(pad = 0, b = 50, l = 50, r = 50))
library(processx)
Fig1
Fig2
fig <- subplot(Fig1, Fig2, nrows = 2) %>% 
  layout(title = '')
fig

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginnen Sie mit den Definitionen von Fig1 und Fig2, untersuchen Sie dann den Aufruf subplot(Fig1, Fig2, nrows = 2) und dessen endgültiges Layout. Führen Sie das Beispiel wie angegeben aus und vergleichen Sie das kombinierte Ergebnis mit jeder eigenständigen Abbildung; abgeschlossen ist es, wenn beide Plots untereinander gerendert werden und ihre dualen y-Achsen getrennt bleiben.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
r
Bereich
data-visualization
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
38/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.