Comments (10)
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.
from ggnewscale.
It's a small wrinkle when get
ing functions. Thanks for bringing into attention, I'll see what I can do!
from ggnewscale.
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 ggplot2
must be loaded.
Thanks for your work on this. A lot of what we do uses overlays, and these have been difficult because of the restrictions of ggplot2
from ggnewscale.
I think it should be fixed in the dev version. Could you install and test it with
devtools::install_github("eliocamp/ggnewscale@dev")
?
from ggnewscale.
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.
from ggnewscale.
Yes, no problem.
match.fun()
/get(mode = "function")
searches for functions in the environment they are called. So match.fun("mean")
searches the environment for a function called "mean" and returns it, but only if mean
is defined in the environment in which match.fun()
is being called.
The guide
argument in ggplot2 scales can be a function or a character with the name of the function. By default it's "colourbar"
or "legend"
depending on the type of scale. The relevant functions are guide_colourbar()
and guide_legend()
, which are defined in the ggplot2 package.
Now, if ggplot2 is not loaded, then neither function is present in the environment, so match.fun("guide_colourbar")
returns an error.
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 new_scale()
, which eventually calls match.fun()
. match.fun()
then looks for a function called "guide_colourbar". In which environment? Well, first it looks it up in the ggnewscale environment, and when it doesn't find it, goes up a level, and so forth until it reaches the global environment. There it finally finds it, if and only if ggplot2 was loaded (or if you had manually defined a function with that name).
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 match.fun()
finds them there. (I also had to change it to get()
because for some reason match.fun()
worked interactively but failed in CMD R Check 🤷♀️️).
I hope this answer is clear enough. The whole environments stuff is rather convoluted and I'm not at all an expert in it.
from ggnewscale.
Ah, sorry. I'll send a patch to CRAN today with the version 0.4.1.
from ggnewscale.
Thanks for that and the explanation.
from ggnewscale.
No problem :)
Version 0.4.1 is now on CRAN and in the master branch.
from ggnewscale.
Thanks again.
from ggnewscale.
Related Issues (20)
- Issue When Trying to Employ `guide_colourbar` ::::: v0.4.8 HOT 5
- Legend issues when using `guides(...)` HOT 4
- Add ability to name scales HOT 7
- ggnewscale CRAN note HOT 3
- Issues with next version of ggplot2 HOT 4
- Question on overriding scales on a pre-existing ggnewscale plot HOT 3
- Release ggnewscale 0.4.9
- Release ggnewscale 0.4.10
- new_scale_colour does not work with a scale_* function that includes a guide argument HOT 4
- `guide` vs. `show.legend` with `new_scale()` HOT 4
- Does not display two scales HOT 2
- Release ggnewscale 0.5.0
- Release ggnewscale 0.4.10 HOT 4
- new_scale_*() throws an error in ggplot2 3.5.0 HOT 4
- New Scales Clear Custom Attributes HOT 2
- setting legend name in `guides` vs. in `scale_manual` with `new_scale()` HOT 1
- Consider implementing guides with custom hastables HOT 1
- "Reverse" implementation HOT 1
- Release ggnewscale 0.5.0 HOT 1
- v0.5.0 does not add new fill scale in some cases HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ggnewscale.