@@ -557,3 +557,36 @@ test_that("May specify legendgroup with through a vector of values", {
557
557
558
558
})
559
559
560
+ test_that(" dual y axis subplot works" , {
561
+ p1 <- plot_ly() %> %
562
+ add_trace(x = 1 : 3 , y = 10 * (1 : 3 )) %> %
563
+ add_trace(x = 2 : 4 , y = 1 : 3 , yaxis = " y2" ) %> %
564
+ layout(yaxis2 = list (overlaying = " y" , side = " right" ))
565
+ p2 <- plot_ly() %> %
566
+ add_trace(x = 3 : 5 , y = (1 : 3 ) ^ 2 ) %> %
567
+ add_trace(x = 4 : 6 , y = (1 : 3 ) ^ 3 , yaxis = " y2" ) %> %
568
+ layout(yaxis2 = list (overlaying = " y" , side = " right" ))
569
+ s <- expect_traces(subplot(p1 , p2 , nrows = 2 , shareX = T ), 4 , " dual-y-axis" )
570
+ yAxes <- sapply(s $ data , `[[` , ' yaxis' )
571
+ names(yAxes ) <- sub(" y" , " yaxis" , yAxes )
572
+
573
+ expect_identical(yAxes [[1 ]], s $ layout [[names(yAxes )[[2 ]]]]$ overlaying )
574
+ expect_identical(yAxes [[3 ]], s $ layout [[names(yAxes )[[4 ]]]]$ overlaying )
575
+ })
576
+
577
+ test_that(" dual x axis subplot works" , {
578
+ p1 <- plot_ly() %> %
579
+ add_trace(x = 1 : 3 , y = 10 * (1 : 3 )) %> %
580
+ add_trace(x = 2 : 4 , y = 1 : 3 , name = " slope of 1" , xaxis = " x2" ) %> %
581
+ layout(xaxis2 = list (overlaying = " x" , side = " top" ))
582
+ p2 <- plot_ly() %> %
583
+ add_trace(x = 3 : 5 , y = (1 : 3 ) ^ 2 , name = " quadratic" ) %> %
584
+ add_trace(x = 4 : 6 , y = (1 : 3 ) ^ 3 , name = " cubic" , xaxis = " x2" ) %> %
585
+ layout(xaxis2 = list (overlaying = " x" , side = " top" ))
586
+ s <- expect_traces(subplot(p1 , p2 ), 4 , " dual-x-axis" )
587
+ xAxes <- sapply(s $ data , `[[` , ' xaxis' )
588
+ names(xAxes ) <- sub(" x" , " xaxis" , xAxes )
589
+
590
+ expect_identical(xAxes [[1 ]], s $ layout [[names(xAxes )[[2 ]]]]$ overlaying )
591
+ expect_identical(xAxes [[3 ]], s $ layout [[names(xAxes )[[4 ]]]]$ overlaying )
592
+ })
0 commit comments