@@ -599,29 +599,6 @@ gg2list <- function(p){
599
599
}
600
600
}
601
601
602
- # avoid redundant legends
603
- fills <- lapply(trace.list , function (x ) paste0(x $ name , " -" , x $ fillcolor ))
604
- linez <- lapply(trace.list , function (x ) paste0(x $ name , " -" , x $ line $ color ))
605
- marks <- lapply(trace.list , function (x ) paste0(x $ name , " -" , x $ marker $ color ))
606
- fill_set <- unlist(fills )
607
- line_set <- unlist(linez )
608
- mark_set <- unlist(marks )
609
- legend_intersect <- function (x , y ) {
610
- i <- intersect(x , y )
611
- # restrict intersection to valid legend entries
612
- i [grepl(" -rgb[a]?\\ (" , i )]
613
- }
614
- # if there is a mark & line legend, get rid of line
615
- t1 <- line_set %in% legend_intersect(mark_set , line_set )
616
- # if there is a mark & fill legend, get rid of fill
617
- t2 <- fill_set %in% legend_intersect(mark_set , fill_set )
618
- # if there is a line & fill legend, get rid of fill
619
- t3 <- fill_set %in% legend_intersect(line_set , fill_set )
620
- t <- t1 | t2 | t3
621
- for (m in seq_along(trace.list ))
622
- if (trace.list [[m ]]$ showlegend && t [m ])
623
- trace.list [[m ]]$ showlegend <- FALSE
624
-
625
602
# Only show a legend title if there is at least 1 trace with
626
603
# showlegend=TRUE.
627
604
trace.showlegend <- sapply(trace.list , " [[" , " showlegend" )
@@ -652,8 +629,6 @@ gg2list <- function(p){
652
629
layout $ annotations <- annotations
653
630
}
654
631
655
-
656
-
657
632
# Family font for text
658
633
if (! is.null(theme.pars $ text $ family )) {
659
634
layout $ titlefont $ family <- theme.pars $ text $ family
@@ -785,6 +760,31 @@ gg2list <- function(p){
785
760
merged.traces [[length(merged.traces )+ 1 ]] <- tr
786
761
}
787
762
763
+ # avoid redundant legends entries
764
+ fills <- lapply(merged.traces , function (x ) paste0(x $ name , " -" , x $ fillcolor ))
765
+ linez <- lapply(merged.traces , function (x ) paste0(x $ name , " -" , x $ line $ color ))
766
+ marks <- lapply(merged.traces , function (x ) paste0(x $ name , " -" ,x $ marker $ color ))
767
+ fill_set <- unlist(fills )
768
+ line_set <- unlist(linez )
769
+ mark_set <- unlist(marks )
770
+ legend_intersect <- function (x , y ) {
771
+ i <- intersect(x , y )
772
+ # restrict intersection to valid legend entries
773
+ i [grepl(" -rgb[a]?\\ (" , i )]
774
+ }
775
+ # if there is a mark & line legend, get rid of line
776
+ t1 <- line_set %in% legend_intersect(mark_set , line_set )
777
+ # that is, unless the mode is 'lines+markers'...
778
+ t1 <- t1 & ! (unlist(lapply(merged.traces , " [[" , " mode" )) %in% " lines+markers" )
779
+ # if there is a mark & fill legend, get rid of fill
780
+ t2 <- fill_set %in% legend_intersect(mark_set , fill_set )
781
+ # if there is a line & fill legend, get rid of fill
782
+ t3 <- fill_set %in% legend_intersect(line_set , fill_set )
783
+ t <- t1 | t2 | t3
784
+ for (m in seq_along(merged.traces ))
785
+ if (isTRUE(merged.traces [[m ]]$ showlegend && t [m ]))
786
+ merged.traces [[m ]]$ showlegend <- FALSE
787
+
788
788
# Put the traces in correct order, according to any manually
789
789
# specified scales. This seems to be repetitive with the trace$rank
790
790
# attribute in layer2traces (which is useful for sorting traces that
0 commit comments