Skip to content

Warning message when adding a manual scale in ggplot #3127

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

Closed
SavasAli opened this issue Feb 11, 2019 · 4 comments · Fixed by #3131
Closed

Warning message when adding a manual scale in ggplot #3127

SavasAli opened this issue Feb 11, 2019 · 4 comments · Fixed by #3131

Comments

@SavasAli
Copy link

On Stackoverflow they suggested to report my question as a bug, so here it is:

When I add a manual scale like in the example below. I get the following error message:
"Warning message: In if (self$guide == "none") return() : the condition has length > 1 and only the first element will be used"

d <- data.frame(week = seq(1, 52, 1), 
            revenue = round(runif(52, 0, 100)), 0)

p <- ggplot(data = d, aes(x = week, y = revenue, fill = 'lightskyblue')) + 
  geom_bar(stat = 'identity', colour = 'black') 


p <- p + scale_fill_identity(name = NULL,
                             guide = guide_legend(label.position = 'top'),
                             labels = c('2019'))
@batpigandme
Copy link
Contributor

Would you mind turning this into a reprex (short for minimal reproducible example)? It's especially helpful for ggplot2, since it automatically generates and uploads the plots (or lack thereof), which makes it much easier to go through at a glance.

If you've never heard of a reprex before, you might want to start by reading the tidyverse.org help page.

reprex is automatically installed with the tidyverse package, but if you don't have it, you can run

install.packages("reprex")

If you run into problems with access to your clipboard, you can specify an outfile for the reprex, and then copy and paste (or drag and drop) the contents here.

reprex::reprex(input = "fruits_stringdist.R", outfile = "fruits_stringdist.md")

Thanks

@batpigandme
Copy link
Contributor

batpigandme commented Feb 11, 2019

You can take the comment above as a "for future reference", since I just ran your code through reprex (below)

library(ggplot2)
d <- data.frame(week = seq(1, 52, 1), 
                revenue = round(runif(52, 0, 100)), 0)

p <- ggplot(data = d, aes(x = week, y = revenue, fill = 'lightskyblue')) + 
  geom_bar(stat = 'identity', colour = 'black') 


p <- p + scale_fill_identity(name = NULL,
                             guide = guide_legend(label.position = 'top'),
                             labels = c('2019'))
p
#> Warning in if (self$guide == "none") return(): the condition has length > 1
#> and only the first element will be used

Created on 2019-02-11 by the reprex package (v0.2.1)

Suggested fix from SO answer:

I imagine the fix should be pretty simple anyway, e.g.:

 # this
if (all(self$guide == "none")) return() 


# instead of this
if (self$guide == "none") return()

@clauswilke
Copy link
Member

clauswilke commented Feb 11, 2019

Code lines that need fixing:

if (self$guide == "none") return()

if (self$guide == "none") return()

This is probably a better fix than the one suggested on SO:

if (isTRUE(self$guide == "none")) return()

clauswilke added a commit to wilkelab/ggplot2_archive that referenced this issue Feb 11, 2019
clauswilke added a commit that referenced this issue Feb 12, 2019
* properly check for presence/absence of guide. Closes #3127.

* use `identical()` instead of `isTRUE()`.
@lock
Copy link

lock bot commented Aug 11, 2019

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Aug 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants