|
18 | 18 | #' lines(x=c(3,4,3), y=c(2,4,6), legend.name="Example Lines", lty=5, col="orange") %>% |
19 | 19 | #' points(x=1, y=2, side=c(3,2), legend.name="Example Points 1", pch=1, col="blue") %>% |
20 | 20 | #' points(x=3, y=4, side=c(1,4), legend.name="Example Points 2", pch=5, col="red") %>% |
21 | | -#' legend(location="topright") |
| 21 | +#' legend(location="topright", title="LEGEND!!!") |
22 | 22 | #' topright |
23 | 23 | #' |
24 | 24 | #' defaultLegend <- gsplot(list()) %>% |
@@ -152,38 +152,41 @@ draw_legend <- function(gsplot) { |
152 | 152 |
|
153 | 153 | smartLegend <- unique(smartLegend) |
154 | 154 |
|
155 | | - #only include pch if we have a non-NA entry for points |
156 | | - if(length(pts_i) > 0) { |
157 | | - legendParams <- append(legendParams, list( |
158 | | - pch=smartLegend$symbol |
159 | | - )) |
160 | | - } |
161 | | - |
162 | | - #only include lty if we have a non-NA entry for lines |
163 | | - if(length(lines_i) > 0) { |
164 | | - legendParams <- append(legendParams, list( |
165 | | - lty=smartLegend$line |
166 | | - )) |
167 | | - } |
| 155 | + if(nrow(smartLegend) > 0){ |
168 | 156 |
|
169 | | - legendParams <- append(legendParams, list( |
170 | | - legend=smartLegend$text, |
171 | | - col=smartLegend$color |
172 | | - )) |
173 | | - |
174 | | - #for above/below, dynamically set the number of columns |
175 | | - location <- gsplot[['legend']][['gs.config']][['location']] |
176 | | - if(location == "below" || location == "above") { |
177 | | - itemsPerCol <- 3 #TODO load this from config |
178 | | - cols <- NROW(smartLegend) %/% 3; |
179 | | - if(NROW(smartLegend) %% 3 > 0) { |
180 | | - cols <- cols + 1 |
| 157 | + #only include pch if we have a non-NA entry for points |
| 158 | + if(length(pts_i) > 0) { |
| 159 | + legendParams <- append(legendParams, list( |
| 160 | + pch=smartLegend$symbol |
| 161 | + )) |
| 162 | + } |
| 163 | + |
| 164 | + #only include lty if we have a non-NA entry for lines |
| 165 | + if(length(lines_i) > 0) { |
| 166 | + legendParams <- append(legendParams, list( |
| 167 | + lty=smartLegend$line |
| 168 | + )) |
181 | 169 | } |
| 170 | + |
182 | 171 | legendParams <- append(legendParams, list( |
183 | | - ncol=cols |
| 172 | + legend=smartLegend$text, |
| 173 | + col=smartLegend$color |
184 | 174 | )) |
| 175 | + |
| 176 | + #for above/below, dynamically set the number of columns |
| 177 | + location <- gsplot[['legend']][['gs.config']][['location']] |
| 178 | + if(location == "below" || location == "above") { |
| 179 | + itemsPerCol <- 3 #TODO load this from config |
| 180 | + cols <- NROW(smartLegend) %/% 3; |
| 181 | + if(NROW(smartLegend) %% 3 > 0) { |
| 182 | + cols <- cols + 1 |
| 183 | + } |
| 184 | + legendParams <- append(legendParams, list( |
| 185 | + ncol=cols |
| 186 | + )) |
| 187 | + } |
| 188 | + legend(legendParams) |
185 | 189 | } |
186 | | - legend(legendParams) |
187 | 190 | } |
188 | 191 | } |
189 | 192 |
|
|
0 commit comments