Skip to content

Commit c1824df

Browse files
committed
Merge branch 'master' of github.com:tdhock/directlabels
2 parents 74f3824 + 8d9df2b commit c1824df

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

R/ggplot2.R

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,22 @@ pkgFun <- function(fun, pkg="ggplot2") {
195195
### Extract guides to hide from a ggplot.
196196
legends2hide <- function(p){
197197
plistextra <- ggplot2::ggplot_build(p)
198+
199+
if ("get_guide_data" %in% getNamespaceExports("ggplot2")) {
200+
# Using clunky get here to avoid R cmd check warnings in earlier versions
201+
# of ggplot2
202+
get_guide_data <- get("get_guide_data", envir = asNamespace("ggplot2"))
203+
for (aes in c("colour", "fill")) {
204+
guide_data <- get_guide_data(plistextra, aes)
205+
if (!is.null(guide_data)) {
206+
hide <- colnames(guide_data)
207+
hide <- hide[!grepl("^\\.", hide)]
208+
return(list(colour = aes, hide = hide, data = guide_data))
209+
}
210+
}
211+
return()
212+
}
213+
198214
plot <- plistextra$plot
199215
scales = plot$scales
200216
layers = plot$layers

0 commit comments

Comments
 (0)