Skip to content
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

Superfluous x-axis label when using hrbthemes::theme_ipsum() #8

Closed
jemus42 opened this issue Mar 24, 2020 · 7 comments
Closed

Superfluous x-axis label when using hrbthemes::theme_ipsum() #8

jemus42 opened this issue Mar 24, 2020 · 7 comments

Comments

@jemus42
Copy link

jemus42 commented Mar 24, 2020

See also: https://stackoverflow.com/questions/60832888/r-ggplot2-plot-with-ggupset-and-hrbrthemestheme-upsum-superfluous-at-app

An extra "at" appears above the x-axis label when using hrbthemes::theme_ipsum() – which is in itself an issue because p + hrbthemes::theme_ipsum() fails in the first place, which I guess is probably the root of the issue.
Here the same reprex as can be found in the linked SO post:

library(ggplot2)
library(dplyr, warn.conflicts = FALSE)
library(ggupset) # https://github.com/const-ae/ggupset
library(hrbrthemes) # https://github.com/hrbrmstr/hrbrthemes

# starting with a perfectly normal upset plot
p <- tidy_movies %>%
  distinct(title, year, length, .keep_all = TRUE) %>%
  head(100) %>% # smaller dataset for faster plotting
  ggplot(aes(x=Genres)) +
  geom_bar() +
  scale_x_upset(order_by = "degree") +
  labs(x = "x-label for demonstration purposes")

# looks fine
p
#> Warning: Removed 30 rows containing non-finite values (stat_count).

# Now with theme_ipsum()...
p_hrbr <- p + hrbrthemes::theme_ipsum()

# But nope, something seems to conflict here.
p_hrbr
#> Warning: Removed 30 rows containing non-finite values (stat_count).
#> Error: Insufficient values in manual scale. 2 needed but only 0 provided.

# But in my actual usecase I set the theme globally, like so:
theme_set(hrbrthemes::theme_ipsum())

# The original plot, with theme_ipsum
p
#> Warning: Removed 30 rows containing non-finite values (stat_count).

# ??? I can't find any label set to "at"
p$labels
#> $x
#> [1] "x-label for demonstration purposes"
#> 
#> $y
#> [1] "count"
#> 
#> $weight
#> [1] "weight"

# Resetting to the default theme:
theme_set(theme_gray())

# It's gone
p
#> Warning: Removed 30 rows containing non-finite values (stat_count).

Session info ``` r

devtools::session_info(pkgs = c("ggplot2", "hrbrthemes", "ggupset"))
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 3.6.3 (2020-02-29)
#> os macOS Catalina 10.15.3
#> system x86_64, darwin15.6.0
#> ui X11
#> language (EN)
#> collate en_US.UTF-8
#> ctype en_US.UTF-8
#> tz Europe/Berlin
#> date 2020-03-24
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date lib source
#> assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.6.0)
#> backports 1.1.5 2019-10-02 [1] CRAN (R 3.6.0)
#> base64enc 0.1-3 2015-07-28 [1] CRAN (R 3.6.0)
#> callr 3.4.2 2020-02-12 [1] CRAN (R 3.6.2)
#> cli 2.0.2 2020-02-28 [1] CRAN (R 3.6.2)
#> colorspace 1.4-1 2019-03-18 [1] CRAN (R 3.6.0)
#> crayon 1.3.4 2017-09-16 [1] CRAN (R 3.6.0)
#> desc 1.2.0 2018-05-01 [1] CRAN (R 3.6.0)
#> digest 0.6.25 2020-02-23 [1] CRAN (R 3.6.0)
#> ellipsis 0.3.0 2019-09-20 [1] CRAN (R 3.6.0)
#> evaluate 0.14 2019-05-28 [1] CRAN (R 3.6.0)
#> extrafont 0.17 2014-12-08 [1] CRAN (R 3.6.0)
#> extrafontdb 1.0 2012-06-11 [1] CRAN (R 3.6.0)
#> fansi 0.4.1 2020-01-08 [1] CRAN (R 3.6.0)
#> farver 2.0.3 2020-01-16 [1] CRAN (R 3.6.0)
#> gdtools 0.2.1 2019-10-14 [1] CRAN (R 3.6.0)
#> ggplot2 * 3.3.0 2020-03-05 [1] CRAN (R 3.6.2)
#> ggupset * 0.1.0 2019-03-06 [1] CRAN (R 3.6.0)
#> glue 1.3.2 2020-03-12 [1] CRAN (R 3.6.0)
#> gtable 0.3.0 2019-03-25 [1] CRAN (R 3.6.0)
#> highr 0.8 2019-03-20 [1] CRAN (R 3.6.0)
#> hrbrthemes * 0.8.0 2020-03-24 [1] Github (hrbrmstr/hrbrthemes@a599f17)
#> htmltools 0.4.0 2019-10-04 [1] CRAN (R 3.6.0)
#> isoband 0.2.0 2019-04-06 [1] CRAN (R 3.6.0)
#> jsonlite 1.6.1 2020-02-02 [1] CRAN (R 3.6.0)
#> knitr 1.28 2020-02-06 [1] CRAN (R 3.6.2)
#> labeling 0.3 2014-08-23 [1] CRAN (R 3.6.0)
#> lattice 0.20-38 2018-11-04 [2] CRAN (R 3.6.3)
#> lifecycle 0.2.0 2020-03-06 [1] CRAN (R 3.6.2)
#> magrittr 1.5 2014-11-22 [1] CRAN (R 3.6.0)
#> markdown 1.1 2019-08-07 [1] CRAN (R 3.6.0)
#> MASS 7.3-51.5 2019-12-20 [2] CRAN (R 3.6.3)
#> Matrix 1.2-18 2019-11-27 [2] CRAN (R 3.6.3)
#> mgcv 1.8-31 2019-11-09 [2] CRAN (R 3.6.3)
#> mime 0.9 2020-02-04 [1] CRAN (R 3.6.0)
#> munsell 0.5.0 2018-06-12 [1] CRAN (R 3.6.0)
#> nlme 3.1-144 2020-02-06 [2] CRAN (R 3.6.3)
#> pillar 1.4.3 2019-12-20 [1] CRAN (R 3.6.0)
#> pkgbuild 1.0.6 2019-10-09 [1] CRAN (R 3.6.0)
#> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 3.6.0)
#> pkgload 1.0.2 2018-10-29 [1] CRAN (R 3.6.0)
#> praise 1.0.0 2015-08-11 [1] CRAN (R 3.6.0)
#> prettyunits 1.1.1 2020-01-24 [1] CRAN (R 3.6.0)
#> processx 3.4.2 2020-02-09 [1] CRAN (R 3.6.0)
#> ps 1.3.2 2020-02-13 [1] CRAN (R 3.6.0)
#> R6 2.4.1 2019-11-12 [1] CRAN (R 3.6.0)
#> RColorBrewer 1.1-2 2014-12-07 [1] CRAN (R 3.6.0)
#> Rcpp 1.0.4 2020-03-17 [1] CRAN (R 3.6.0)
#> rlang 0.4.5 2020-03-01 [1] CRAN (R 3.6.0)
#> rmarkdown 2.1 2020-01-20 [1] CRAN (R 3.6.0)
#> rprojroot 1.3-2 2018-01-03 [1] CRAN (R 3.6.0)
#> rstudioapi 0.11 2020-02-07 [1] CRAN (R 3.6.0)
#> Rttf2pt1 1.3.8 2020-01-10 [1] CRAN (R 3.6.0)
#> scales 1.1.0 2019-11-18 [1] CRAN (R 3.6.0)
#> stringi 1.4.6 2020-02-17 [1] CRAN (R 3.6.0)
#> stringr 1.4.0 2019-02-10 [1] CRAN (R 3.6.0)
#> systemfonts 0.1.1 2019-07-01 [1] CRAN (R 3.6.0)
#> testthat 2.3.2 2020-03-02 [1] CRAN (R 3.6.0)
#> tibble 2.1.3 2019-06-06 [1] CRAN (R 3.6.0)
#> tinytex 0.20 2020-02-25 [1] CRAN (R 3.6.0)
#> utf8 1.1.4 2018-05-24 [1] CRAN (R 3.6.0)
#> vctrs 0.2.4 2020-03-10 [1] CRAN (R 3.6.0)
#> viridisLite 0.3.0 2018-02-01 [1] CRAN (R 3.6.0)
#> withr 2.1.2 2018-03-15 [1] CRAN (R 3.6.0)
#> xfun 0.12 2020-01-13 [1] CRAN (R 3.6.0)
#> yaml 2.2.1 2020-02-01 [1] CRAN (R 3.6.0)
#>
#> [1] /Users/Lukas/Library/R/3.6
#> [2] /Library/Frameworks/R.framework/Versions/3.6/Resources/library

</details>
<sup>Created on 2020-03-24 by the [reprex package](https://reprex.tidyverse.org) (v0.3.0)</sup>
@const-ae
Copy link
Owner

Well, that is a fun issue.

FIrst, of all thanks for the great reproducible example. I also get the same "at" if the theme is set globally.

An easy way to get rid of it, seems to be to set the theme before adding the scale_x_upset() to the plot:

library(ggplot2)
library(dplyr, warn.conflicts = FALSE)
library(ggupset) # https://github.com/const-ae/ggupset
library(hrbrthemes) # https://github.com/hrbrmstr/hrbrthemes

tidy_movies %>%
  distinct(title, year, length, .keep_all = TRUE) %>%
  head(100) %>% # smaller dataset for faster plotting
  ggplot(aes(x=Genres)) +
  geom_bar() +
  hrbrthemes::theme_ipsum() +
  scale_x_upset(order_by = "degree") +
  labs(x = "x-label for demonstration purposes")
#> Warning: Removed 30 rows containing non-finite values (stat_count).

tidy_movies %>%
  distinct(title, year, length, .keep_all = TRUE) %>%
  head(100) %>% # smaller dataset for faster plotting
  ggplot(aes(x=Genres)) +
  geom_bar() +
  scale_x_upset(order_by = "degree") +
  hrbrthemes::theme_ipsum() +
  labs(x = "x-label for demonstration purposes")
#> Warning: Removed 30 rows containing non-finite values (stat_count).
#> Error: Insufficient values in manual scale. 2 needed but only 0 provided.

Created on 2020-03-24 by the reprex package (v0.3.0)

This suggests to me that there is some bad interaction going on with the theme() that ggupset is adding and the theme_ipsum(). I will investigate further to see what is actually going on there.

@jemus42
Copy link
Author

jemus42 commented Mar 24, 2020

Ah, I forgot to include that step in my "wtf is happening" process when making the reprex!

I tried that variant too, but since I set the theme globally specifically so that I don't have to add it to each plot (and my actual theme is theme_ipsum(...) + theme(bunch of other stuff)) I'd like to avoid that approach if the "global option" is available, but I guess I'll work around it for now.

For what it's worth, the author of hrbrthemes suggested it might be an issue regarding recent ggplot2 changes.

Anyway, thanks for taking a look so quickly!
I was afraid the package might be slightly abandoned after seeing it hasn't been touched recently, so I'm really glad you're still on it!

@const-ae
Copy link
Owner

Yeah, you are right. It is not good that global themes break the behavior of ggupset.

I think I have actually found the source of the "at" (https://github.com/const-ae/ggupset/blob/master/R/axis_combmatrix.R#L240). I add the combination matrix as a separate plot and then use my own theme to hide the x-axis label (https://github.com/const-ae/ggupset/blob/master/R/axis_combmatrix.R#L259).
Now, if you have a global theme, the combination matrix plot is also styled and now the axis label is displayed.
I guess the solution will be to set xlab("") in the combination plot. However, I am currently in a call and will try the fix afterwards :)

For what it's worth, the author of hrbrthemes suggested it might be an issue regarding recent ggplot2 changes.

Yeah, I recently saw their blogpost and was wondering if this would break the package. I just didn't have the time to pro-actively investigate and am just waiting for the bug reports ;)

const-ae added a commit that referenced this issue Mar 24, 2020
If a global theme specified axis.title.x, this over-wrote the behavior
of axis.title that I was setting.
@const-ae
Copy link
Owner

I have fixed two problems that were in ggupset with non-default themes.

  1. Make sure that the hidden elements from the combination matrix plot don't suddenly appear
  2. Make sure that if a theme is added after the theme_combmatrix() the method still finds some good defaults
library(ggplot2)
library(dplyr, warn.conflicts = FALSE)
library(ggupset) # https://github.com/const-ae/ggupset

# starting with a perfectly normal upset plot
p <- tidy_movies %>%
  distinct(title, year, length, .keep_all = TRUE) %>%
  head(100) %>% # smaller dataset for faster plotting
  ggplot(aes(x=Genres)) +
  geom_bar() +
  scale_x_upset(order_by = "degree") +
  labs(x = "x-label for demonstration purposes")

# fine
p
#> Warning: Removed 30 rows containing non-finite values (stat_count).

# fine
p + hrbrthemes::theme_ipsum()
#> Warning: Removed 30 rows containing non-finite values (stat_count).

theme_set(hrbrthemes::theme_ipsum())
# fine
p
#> Warning: Removed 30 rows containing non-finite values (stat_count).

Created on 2020-03-25 by the reprex package (v0.3.0)

I will try and submit a new version to CRAN in the next days. In the mean time you can use the fixed version by installing the development version from Github devtools::install_github("const-ae/ggupset").
I will now close this issue. If you have any more questions or feel that I forgot to address something, feel free to comment / reopen.

@jemus42
Copy link
Author

jemus42 commented Mar 25, 2020

Awesome, thanks a lot!

(I already started using the GH version yesterday after I saw d9b1d01 :)

@const-ae
Copy link
Owner

Great, note that I also fixed some more problems with eaef4a7

@const-ae
Copy link
Owner

Fix is on CRAN: https://cran.r-project.org/package=ggupset

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants