-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ggplot2 imports when used in a package #21
Comments
okay a reproducible example. To run this you will need to have installed the packages 'rerddap' and 'plotdap' and the packages they depend on. library(rerddap)
library(plotdap)
murSST_west <- griddap(
'jplMURSST41',
latitude = c(22, 51),
longitude = c(-140, -105),
time = c('last', 'last'),
fields = 'analysed_sst'
)
p <- add_griddap(plotdap(),
murSST_west,
~analysed_sst,
fill = 'thermal'
)
library(ggnewscale)
p$ggplot <- p$ggplot + new_scale_colour()
Error in get(as.character(FUN), mode = "function", envir = envir) :
object 'guide_colourbar' of mode 'function' was not found
library(ggplot2)
p$ggplot <- p$ggplot + new_scale_colour() This suggests that somewhere guide_colourbar is not properly imported, though I could be wrong. |
It's a small wrinkle when |
Thanks. I was able to isolate the line in your code where it was occurring, but it was beyond what I know. Let me know if you think you have a fix, I will test it. Otherwise in the examples in my package that use this, i will just note that Thanks for your work on this. A lot of what we do uses overlays, and these have been difficult because of the restrictions of |
I think it should be fixed in the dev version. Could you install and test it with devtools::install_github("eliocamp/ggnewscale@dev") ? |
Just did two quick test, including the overlay which I have as an example which was causing this, and they worked fine. Perfect thank you. When you submit this to CRAN, what will be the version number? I will make certain my imports require that version or higher. If you have the time and feel like it, could you explain to me the issue. As I said, I looked at your code, found the line (it was in match.fun) but couldn't see what was doing it and was hoping to learn both the problem and the fix. |
Yes, no problem.
The match.fun("guide_colourbar")
#> Error in get(as.character(FUN), mode = "function", envir = envir): object 'guide_colourbar' of mode 'function' was not found
library(ggplot2)
match.fun("guide_colourbar")
#> function (title = waiver(), title.position = NULL, title.theme = NULL,
#> title.hjust = NULL, title.vjust = NULL, label = TRUE, label.position = NULL,
#> label.theme = NULL, label.hjust = NULL, label.vjust = NULL,
#> barwidth = NULL, barheight = NULL, nbin = 20, raster = TRUE,
#> frame.colour = NULL, frame.linewidth = 0.5, frame.linetype = 1,
#> ticks = TRUE, ticks.colour = "white", ticks.linewidth = 0.5,
#> draw.ulim = TRUE, draw.llim = TRUE, direction = NULL, default.unit = "line",
#> reverse = FALSE, order = 0, available_aes = c("colour", "color",
#> "fill"), ...)
#> {
#> if (!is.null(barwidth) && !is.unit(barwidth))
#> barwidth <- unit(barwidth, default.unit)
#> if (!is.null(barheight) && !is.unit(barheight))
#> barheight <- unit(barheight, default.unit)
#> structure(list(title = title, title.position = title.position,
#> title.theme = title.theme, title.hjust = title.hjust,
#> title.vjust = title.vjust, label = label, label.position = label.position,
#> label.theme = label.theme, label.hjust = label.hjust,
#> label.vjust = label.vjust, barwidth = barwidth, barheight = barheight,
#> nbin = nbin, raster = raster, frame.colour = frame.colour,
#> frame.linewidth = frame.linewidth, frame.linetype = frame.linetype,
#> ticks = ticks, ticks.colour = ticks.colour, ticks.linewidth = ticks.linewidth,
#> draw.ulim = draw.ulim, draw.llim = draw.llim, direction = direction,
#> default.unit = default.unit, reverse = reverse, order = order,
#> available_aes = available_aes, ..., name = "colorbar"),
#> class = c("guide", "colorbar"))
#> }
#> <bytecode: 0x55f2a3c19680>
#> <environment: namespace:ggplot2> Created on 2020-02-13 by the reprex package (v0.3.0) In your example, you call The solution was for me to import both functions into the ggnewscale package here. This makes it so that they are available in the ggnewscale environment, so that I hope this answer is clear enough. The whole environments stuff is rather convoluted and I'm not at all an expert in it. |
Ah, sorry. I'll send a patch to CRAN today with the version 0.4.1. |
Thanks for that and the explanation. |
No problem :) |
Thanks again. |
I am having an issue when using ggnewscale from within a package. It is pretty difficult to make a reproducible example because it depends on being in my package, which is a new version of the package 'plotdap'. 'plotdap' has its own object, but embedded in that object is a ggplot object, so let's call the 'plotdap' object 'plot' and the ggplot object is then plot$ggplot. I import ggnewscale in my Description, and the line I am trying is:
okay so if do that on a plot where I need to set a new scale I get the following:
Now this is what leaves me mystified. If i now do
library(ggplot2)
and try the exact same command (the command is a 'plotdap' command more complicated than the one line, but that is where it fails) it works. So somehow a reference to something in ggplot2 is not being found. I am stumped on this one. I looked at the
bump_aes_scale()
function and don't see why that should make a difference. I haven't posted this new version of 'plotdap' yet because I have been experimenting with using 'ggnewscale', but I could post it. I could then give a complete reproducible example. Basically I am trying to overlay a table like example (points) on a grid.I should add that the first plot 'p' because it uses 'sf' has both a scale_colour_gradientn and a scale_fill_gradientn but with ggplot2::guides(colour = "none").
I mention the late because I was wondering because
bump_aes_scale()
tests for this if for some reason it is not catching it.If you have any suggestions would appreciate it.
-Roy
The text was updated successfully, but these errors were encountered: