Comments (4)
Ups, my bad.
Wow, this was indeed a trip!
The warning comes from ggplot2 side, I think, since it only shows up at print time. I can remove it by switching to "new_colour" instead of "colour_new" for the new aesthetics.
The result is this, however:
library(ggplot2)
options(warnPartialMatchDollar = TRUE)
ggplot(mpg, aes(displ, hwy)) +
geom_point(aes(colour = factor(year)), size = 5) +
scale_colour_brewer("year", type = "qual", palette = 5) +
ggnewscale::new_scale_colour() +
geom_point(aes(colour = cyl == 4), size = 1, fill = NA) +
scale_colour_manual("4 cylinder", values = c("grey60", "black"))
Which basically breaks part of the functionallity.
The root of the issue is reeealy convoluted.
I traced the warning to the part of the code that draws guides. In this example, partial matching is done in this part of draw_key_point
pointsGrob(0.5, 0.5, pch = data$shape, gp = gpar(col = alpha(data$colour %||% # <- here!
"black", data$alpha), fill = alpha(data$fill %||% "black",
data$alpha), fontsize = (data$size %||% 1.5) * .pt +
(data$stroke %||% 0.5) * .stroke/2, lwd = (data$stroke %||%
0.5) * .stroke/2))
The problem is that the guide key looks like this:
$key
colour_new .label
1 #B3E2CD 1999
2 #FDCDAC 2008
This comes from this part of guide_train.legend:
function (guide, scale, aesthetic = NULL) {
# ....
aes_column_name <- aesthetic %||% scale$aesthetics[1] # <- here!
key <- new_data_frame(setNames(list(scale$map(breaks)), aes_column_name))
#...
It would be awesome if ggnewscale could overwrite the aesthetic
variable, but it comes directly from
giudes_train <- function (scales, theme, guides, labels) {
gdefs <- list()
for (scale in scales$scales) {
for (output in scale$aesthetics) { # output is defined here
guide <- resolve_guide(output, scale, guides)
# ....
guide <- guide_train(guide, scale, output) # and used as the 'aesthetic' argument in guide_train here
# ....
}
After many convoluted attempts, I realised that guide_geom
modifies the key thingy by using geom$use_defaults()
. The simplest fix was to modify the new_geom
generated by ggnewscale:::bump_aes_layer()
with this:
use_defaults <- new_geom$use_defaults
new_geom$use_defaults <- function(...) {
data <- use_defaults(...)
colnames(data)[colnames(data) == new_aes] <- old_aes
data
}
Annnnd, BINGO!
library(ggplot2)
options(warnPartialMatchDollar = TRUE)
ggplot(mpg, aes(displ, hwy)) +
geom_point(aes(colour = factor(year)), size = 5) +
scale_colour_brewer("year", type = "qual", palette = 5) +
ggnewscale::new_scale_colour() +
geom_point(aes(colour = cyl == 4), size = 1, fill = NA) +
scale_colour_manual("4 cylinder", values = c("grey60", "black"))
Created on 2020-07-31 by the reprex package (v0.3.0)
from ggnewscale.
Thanks!
I'm not seeing that warning. I was on 3.6 and though it might be from 4.0, but I upgraded and it's still not there. I attach my system information.
library(ggplot2)
options(warnPartialMatchArgs = TRUE)
ggplot(mpg, aes(displ, hwy)) +
geom_point(aes(colour = factor(year)), size = 5) +
scale_colour_brewer("year", type = "qual", palette = 5) +
ggnewscale::new_scale_colour() +
geom_point(aes(colour = cyl == 4), size = 1, fill = NA) +
scale_colour_manual("4 cylinder", values = c("grey60", "black"))
Created on 2020-07-30 by the reprex package (v0.3.0)
Session info
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.0.2 (2020-06-22)
#> os elementary OS 5.1.6 Hera
#> system x86_64, linux-gnu
#> ui X11
#> language en_GB:en
#> collate en_GB.UTF-8
#> ctype en_GB.UTF-8
#> tz America/Argentina/Buenos_Aires
#> date 2020-07-30
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date lib source
#> assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.0.2)
#> backports 1.1.8 2020-06-17 [1] CRAN (R 4.0.2)
#> callr 3.4.3 2020-03-28 [1] CRAN (R 4.0.2)
#> cli 2.0.2 2020-02-28 [1] CRAN (R 4.0.2)
#> colorspace 1.4-1 2019-03-18 [1] CRAN (R 4.0.2)
#> crayon 1.3.4 2017-09-16 [1] CRAN (R 4.0.2)
#> curl 4.3 2019-12-02 [1] CRAN (R 4.0.2)
#> desc 1.2.0 2018-05-01 [1] CRAN (R 4.0.2)
#> devtools 2.3.1 2020-07-21 [1] CRAN (R 4.0.2)
#> digest 0.6.25 2020-02-23 [1] CRAN (R 4.0.2)
#> ellipsis 0.3.1 2020-05-15 [1] CRAN (R 4.0.2)
#> evaluate 0.14 2019-05-28 [1] CRAN (R 4.0.2)
#> fansi 0.4.1 2020-01-08 [1] CRAN (R 4.0.2)
#> farver 2.0.3 2020-01-16 [1] RSPM (R 4.0.2)
#> fs 1.4.2 2020-06-30 [1] CRAN (R 4.0.2)
#> ggnewscale 0.4.1 2020-07-30 [1] Github (eliocamp/ggnewscale@1884db3)
#> ggplot2 * 3.3.2 2020-06-19 [1] RSPM (R 4.0.2)
#> glue 1.4.1 2020-05-13 [1] CRAN (R 4.0.2)
#> gtable 0.3.0 2019-03-25 [1] RSPM (R 4.0.2)
#> highr 0.8 2019-03-20 [1] CRAN (R 4.0.2)
#> htmltools 0.5.0 2020-06-16 [1] CRAN (R 4.0.2)
#> httr 1.4.2 2020-07-20 [1] CRAN (R 4.0.2)
#> knitr 1.29 2020-06-23 [1] CRAN (R 4.0.2)
#> labeling 0.3 2014-08-23 [1] CRAN (R 4.0.2)
#> lifecycle 0.2.0 2020-03-06 [1] CRAN (R 4.0.2)
#> magrittr 1.5 2014-11-22 [1] CRAN (R 4.0.2)
#> memoise 1.1.0 2017-04-21 [1] CRAN (R 4.0.2)
#> mime 0.9 2020-02-04 [1] CRAN (R 4.0.2)
#> munsell 0.5.0 2018-06-12 [1] RSPM (R 4.0.2)
#> pillar 1.4.6 2020-07-10 [1] CRAN (R 4.0.2)
#> pkgbuild 1.1.0 2020-07-13 [1] CRAN (R 4.0.2)
#> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.0.2)
#> pkgload 1.1.0 2020-05-29 [1] CRAN (R 4.0.2)
#> prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.0.2)
#> processx 3.4.3 2020-07-05 [1] CRAN (R 4.0.2)
#> ps 1.3.3 2020-05-08 [1] CRAN (R 4.0.2)
#> R6 2.4.1 2019-11-12 [1] CRAN (R 4.0.2)
#> RColorBrewer 1.1-2 2014-12-07 [1] CRAN (R 4.0.2)
#> remotes 2.2.0 2020-07-21 [1] CRAN (R 4.0.2)
#> rlang 0.4.7 2020-07-09 [1] CRAN (R 4.0.2)
#> rmarkdown 2.3 2020-06-18 [1] RSPM (R 4.0.2)
#> rprojroot 1.3-2 2018-01-03 [1] CRAN (R 4.0.2)
#> scales 1.1.1 2020-05-11 [1] RSPM (R 4.0.2)
#> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 4.0.2)
#> stringi 1.4.6 2020-02-17 [1] CRAN (R 4.0.2)
#> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.0.2)
#> testthat 2.3.2 2020-03-02 [1] CRAN (R 4.0.2)
#> tibble 3.0.3 2020-07-10 [1] CRAN (R 4.0.2)
#> usethis 1.6.1 2020-04-29 [1] CRAN (R 4.0.2)
#> vctrs 0.3.2 2020-07-15 [1] CRAN (R 4.0.2)
#> withr 2.2.0 2020-04-20 [1] CRAN (R 4.0.2)
#> xfun 0.16 2020-07-24 [1] CRAN (R 4.0.2)
#> xml2 1.3.2 2020-04-23 [1] CRAN (R 4.0.2)
#> yaml 2.2.1 2020-02-01 [1] CRAN (R 4.0.2)
#>
#> [1] /home/elio/R/x86_64-pc-linux-gnu-library/4.0
#> [2] /usr/local/lib/R/site-library
#> [3] /usr/lib/R/site-library
#> [4] /usr/lib/R/library
from ggnewscale.
I accidentally included the wrong option when I first posted (and then I think you missed my edit) — you need options(warnPartialMatchDollar = TRUE)
from ggnewscale.
Reopening, as it created #25
from ggnewscale.
Related Issues (20)
- Release ggnewscale 0.4.8
- 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
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.