How to display emojis in ggplot2 using emo package in R? - r

I am trying to use ggplot2 to plot some graphs with emojis shown as labels using the emo package. I've learned it from this post, but it's simply not working.
I have tried the emojifont package before, but it's a font type that renders emojis in black and white and it requires opening a new graphics device using e.g. quartz().
To go around the color problem, Tino has suggested (refer to the post above) using the gridSVG package, i.e. after creating a new graphics device and plotting with emojifont, save the graph ps = grid.export("emoji.svg", addClass=T) on local disk as a .svg file that renders emojis in a colorful style.
I would really appreciate a solution that (a) gives colorful emojis and (b) showing the graph directly, which is compatible with routine ggplot use cases.
library(ggplot2)
library(emo)
names = c("smile","school","office","blush","smirk","heart_eyes")
n = length(names):1
e = sapply(names, emo::ji)
dat = data.frame(emoji_name = names, n = n, emoji = e, stringsAsFactors = F)
ggplot(data=dat, aes(emoji_name, n)) +
geom_bar(stat = "identity") +
scale_x_discrete(breaks = dat$emoji_name, labels = dat$emoji) +
coord_flip()
My R version is
> sessionInfo()
R version 3.4.4 (2018-03-15)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12

use the emojifont package :)
read more here
library(ggplot2)
library(emojifont)
names = c("smile","school","office","blush","smirk","heart_eyes")
n = length(names):1
e = sapply(names, emojifont::emoji)
dat = data.frame(emoji_name = names, n = n, emoji = e, stringsAsFactors = F)
ggplot(data=dat, aes(emoji_name, n)) +
geom_bar(stat = "identity") +
scale_x_discrete(breaks = dat$emoji_name, labels = dat$emoji) +
theme( axis.text.y =element_text( size=20 ) ) +
coord_flip()
> sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

library(ggplot2)
library(dplyr)
library(purrr)
#remotes::install_github("hadley/emo")
library(emo)
dat <- tibble(names = c("smile","school","office","blush","smirk","heart_eyes"),
emoji = map_chr(names, emo::ji)) %>%
tibble::rowid_to_column("n")
dat %>% ggplot(aes(n, emoji)) +
geom_col(orientation="y") +
theme(axis.text.y = element_text(size = 18))
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 3.6.3 (2020-02-29)
#> os Ubuntu 18.04.4 LTS
#> system x86_64, linux-gnu
#> ui X11
#> language en_GB:en
#> collate en_GB.UTF-8
#> ctype en_GB.UTF-8
#> tz Europe/Oslo
#> date 2020-04-07
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date lib source
#> assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.6.0)
#> cli 2.0.2 2020-02-28 [1] CRAN (R 3.6.3)
#> 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)
#> digest 0.6.25 2020-02-23 [1] CRAN (R 3.6.3)
#> dplyr * 0.8.5 2020-03-07 [1] CRAN (R 3.6.3)
#> ellipsis 0.3.0 2019-09-20 [1] CRAN (R 3.6.1)
#> emo * 0.0.0.9000 2020-04-07 [1] Github (hadley/emo#3f03b11)
#> evaluate 0.14 2019-05-28 [1] CRAN (R 3.6.0)
#> fansi 0.4.1 2020-01-08 [1] CRAN (R 3.6.2)
#> farver 2.0.3 2020-01-16 [1] CRAN (R 3.6.2)
#> generics 0.0.2 2018-11-29 [1] CRAN (R 3.6.0)
#> ggplot2 * 3.3.0 2020-03-05 [1] CRAN (R 3.6.3)
#> glue 1.4.0 2020-04-03 [1] CRAN (R 3.6.3)
#> 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)
#> htmltools 0.4.0 2019-10-04 [1] CRAN (R 3.6.1)
#> knitr 1.28 2020-02-06 [1] CRAN (R 3.6.3)
#> labeling 0.3 2014-08-23 [1] CRAN (R 3.6.0)
#> lifecycle 0.2.0 2020-03-06 [1] CRAN (R 3.6.3)
#> lubridate 1.7.8 2020-04-06 [1] CRAN (R 3.6.3)
#> magrittr 1.5 2014-11-22 [1] CRAN (R 3.6.3)
#> munsell 0.5.0 2018-06-12 [1] CRAN (R 3.6.0)
#> pillar 1.4.3 2019-12-20 [1] CRAN (R 3.6.2)
#> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 3.6.1)
#> purrr * 0.3.3 2019-10-18 [1] CRAN (R 3.6.1)
#> R6 2.4.1 2019-11-12 [1] CRAN (R 3.6.1)
#> Rcpp 1.0.4 2020-03-17 [1] CRAN (R 3.6.3)
#> rlang 0.4.5 2020-03-01 [1] CRAN (R 3.6.3)
#> rmarkdown 2.1 2020-01-20 [1] CRAN (R 3.6.3)
#> scales 1.1.0.9000 2020-04-03 [1] local
#> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.6.0)
#> stringi 1.4.6 2020-02-17 [1] CRAN (R 3.6.3)
#> stringr 1.4.0 2019-02-10 [1] CRAN (R 3.6.0)
#> tibble 3.0.0 2020-03-30 [1] CRAN (R 3.6.3)
#> tidyselect 1.0.0 2020-01-27 [1] CRAN (R 3.6.3)
#> vctrs 0.2.4 2020-03-10 [1] CRAN (R 3.6.3)
#> withr 2.1.2 2018-03-15 [1] CRAN (R 3.6.0)
#> xfun 0.12 2020-01-13 [1] CRAN (R 3.6.2)
#> yaml 2.2.1 2020-02-01 [1] CRAN (R 3.6.2)
#>
#> [1] /home/dm0737pe/R/x86_64-pc-linux-gnu-library/3.6
#> [2] /usr/local/lib/R/site-library
#> [3] /usr/lib/R/site-library
#> [4] /usr/lib/R/library
Created on 2020-04-07 by the reprex package (v0.3.0)

Related

ggstatsplot grouped_* function: Error in unique.default(x, nmax = nmax) : unique() applies only to vectors

I have seen this question asked by a number of people with different issues, but I have not found a response that fixes my problem.
I am having a problem with the following error when executing any of the grouped_* commands in ggstatsplot.
Error in unique.default(x, nmax = nmax) : unique() applies only to vectors
I have tried reinstalling R, reinstalling RStudio, and reinstalling all packages. I have also brought this up to the developer of ggstatsplot, but he said he cannot reproduce my error. I expect ggstatsplot to produce grouped plots based on the grouping variable. Instead, I receive the error above.
Here is a reprex with my sessionInfo and the traceback of the problem I am encountering.
If anyone has any idea what is going on here I would greatly appreciate it. Thank you.
Reprex with sessionInfo:
library(ggstatsplot)
#> You can cite this package as:
#> Patil, I. (2021). Visualizations with statistical details: The 'ggstatsplot' approach.
#> Journal of Open Source Software, 6(61), 3167, doi:10.21105/joss.03167
# Error in ggstatsplot grouping function
grouped_ggscatterstats(data = movies_long,
x = budget,
y = rating,
grouping.var = genre)
#> Error in unique.default(x, nmax = nmax): unique() applies only to vectors
Created on 2023-02-07 with reprex v2.0.2
Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.0.3 (2020-10-10)
#> os Ubuntu 20.04.5 LTS
#> system x86_64, linux-gnu
#> ui X11
#> language en_CA:en
#> collate en_CA.UTF-8
#> ctype en_CA.UTF-8
#> tz America/Edmonton
#> date 2023-02-07
#> pandoc 2.19.2 # /usr/lib/rstudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date (UTC) lib source
#> BayesFactor 0.9.12-4.4 2022-07-05 [1] CRAN (R 4.0.3)
#> bayestestR 0.13.0 2022-09-18 [1] CRAN (R 4.0.3)
#> cli 3.6.0 2023-01-09 [1] CRAN (R 4.0.3)
#> coda 0.19-4 2020-09-30 [1] CRAN (R 4.0.3)
#> codetools 0.2-18 2020-11-04 [4] CRAN (R 4.0.3)
#> colorspace 2.1-0 2023-01-23 [1] CRAN (R 4.0.3)
#> correlation 0.8.3 2022-10-09 [1] CRAN (R 4.0.3)
#> curl 5.0.0 2023-01-12 [1] CRAN (R 4.0.3)
#> datawizard 0.6.5 2022-12-14 [1] CRAN (R 4.0.3)
#> digest 0.6.31 2022-12-11 [1] CRAN (R 4.0.3)
#> dplyr 1.1.0 2023-01-29 [1] CRAN (R 4.0.3)
#> effectsize 0.8.3 2023-01-28 [1] CRAN (R 4.0.3)
#> emmeans 1.7.3 2022-03-27 [1] CRAN (R 4.0.3)
#> estimability 1.4.1 2022-08-05 [1] CRAN (R 4.0.3)
#> evaluate 0.20 2023-01-17 [1] CRAN (R 4.0.3)
#> fansi 1.0.4 2023-01-22 [1] CRAN (R 4.0.3)
#> farver 2.1.1 2022-07-06 [1] CRAN (R 4.0.3)
#> fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.0.3)
#> fs 1.6.1 2023-02-06 [1] CRAN (R 4.0.3)
#> generics 0.1.3 2022-07-05 [1] CRAN (R 4.0.3)
#> ggplot2 3.4.0 2022-11-04 [1] CRAN (R 4.0.3)
#> ggside 0.2.2 2022-12-04 [1] CRAN (R 4.0.3)
#> ggstatsplot * 0.10.0 2022-11-27 [1] CRAN (R 4.0.3)
#> glue 1.6.2 2022-02-24 [1] CRAN (R 4.0.3)
#> gtable 0.3.1 2022-09-01 [1] CRAN (R 4.0.3)
#> highr 0.10 2022-12-22 [1] CRAN (R 4.0.3)
#> htmltools 0.5.4 2022-12-07 [1] CRAN (R 4.0.3)
#> httr 1.4.4 2022-08-17 [1] CRAN (R 4.0.3)
#> insight 0.19.0 2023-01-30 [1] CRAN (R 4.0.3)
#> knitr 1.42 2023-01-25 [1] CRAN (R 4.0.3)
#> labeling 0.4.2 2020-10-20 [1] CRAN (R 4.0.3)
#> lattice 0.20-45 2021-09-22 [4] CRAN (R 4.1.1)
#> lifecycle 1.0.3 2022-10-07 [1] CRAN (R 4.0.3)
#> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.0.3)
#> MASS 7.3-58.1 2022-08-03 [4] CRAN (R 4.2.1)
#> Matrix 1.5-3 2022-11-11 [1] CRAN (R 4.0.3)
#> MatrixModels 0.5-1 2022-09-11 [1] CRAN (R 4.0.3)
#> mgcv 1.8-41 2022-10-21 [4] CRAN (R 4.2.1)
#> mime 0.12 2021-09-28 [1] CRAN (R 4.0.3)
#> multcomp 1.4-20 2022-08-07 [1] CRAN (R 4.0.3)
#> munsell 0.5.0 2018-06-12 [1] CRAN (R 4.0.2)
#> mvtnorm 1.1-3 2021-10-08 [1] CRAN (R 4.0.3)
#> nlme 3.1-149 2020-08-23 [4] CRAN (R 4.0.2)
#> paletteer 1.5.0 2022-10-19 [1] CRAN (R 4.0.3)
#> parameters 0.20.2 2023-01-27 [1] CRAN (R 4.0.3)
#> patchwork 1.1.2 2022-08-19 [1] CRAN (R 4.0.3)
#> pbapply 1.7-0 2023-01-13 [1] CRAN (R 4.0.3)
#> performance 0.10.2 2023-01-12 [1] CRAN (R 4.0.3)
#> pillar 1.8.1 2022-08-19 [1] CRAN (R 4.0.3)
#> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.0.2)
#> purrr 1.0.1 2023-01-10 [1] CRAN (R 4.0.3)
#> R.cache 0.16.0 2022-07-21 [1] CRAN (R 4.0.3)
#> R.methodsS3 1.8.2 2022-06-13 [1] CRAN (R 4.0.3)
#> R.oo 1.25.0 2022-06-12 [1] CRAN (R 4.0.3)
#> R.utils 2.12.2 2022-11-11 [1] CRAN (R 4.0.3)
#> R6 2.5.1 2021-08-19 [1] CRAN (R 4.0.3)
#> Rcpp 1.0.10 2023-01-22 [1] CRAN (R 4.0.3)
#> rematch2 2.1.2 2020-05-01 [1] CRAN (R 4.0.2)
#> reprex 2.0.2 2022-08-17 [1] CRAN (R 4.0.3)
#> rlang 1.0.6 2022-09-24 [1] CRAN (R 4.0.3)
#> rmarkdown 2.20 2023-01-19 [1] CRAN (R 4.0.3)
#> rstudioapi 0.14 2022-08-22 [1] CRAN (R 4.0.3)
#> sandwich 3.0-2 2022-06-15 [1] CRAN (R 4.0.3)
#> scales 1.2.1 2022-08-20 [1] CRAN (R 4.0.3)
#> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.0.3)
#> statsExpressions 1.4.0 2023-01-14 [1] CRAN (R 4.0.3)
#> stringi 1.7.12 2023-01-11 [1] CRAN (R 4.0.3)
#> stringr 1.5.0 2022-12-02 [1] CRAN (R 4.0.3)
#> styler 1.9.0 2023-01-15 [1] CRAN (R 4.0.3)
#> survival 3.4-0 2022-08-09 [4] CRAN (R 4.2.1)
#> TH.data 1.1-1 2022-04-26 [1] CRAN (R 4.0.3)
#> tibble 3.1.8 2022-07-22 [1] CRAN (R 4.0.3)
#> tidyr 1.3.0 2023-01-24 [1] CRAN (R 4.0.3)
#> tidyselect 1.2.0 2022-10-10 [1] CRAN (R 4.0.3)
#> utf8 1.2.3 2023-01-31 [1] CRAN (R 4.0.3)
#> vctrs 0.5.2 2023-01-23 [1] CRAN (R 4.0.3)
#> withr 2.5.0 2022-03-03 [1] CRAN (R 4.0.3)
#> xfun 0.37 2023-01-31 [1] CRAN (R 4.0.3)
#> xml2 1.3.3 2021-11-30 [1] CRAN (R 4.0.3)
#> xtable 1.8-4 2019-04-21 [1] CRAN (R 4.0.2)
#> yaml 2.3.7 2023-01-23 [1] CRAN (R 4.0.3)
#> zeallot 0.1.0 2018-01-28 [1] CRAN (R 4.0.3)
#> zoo 1.8-11 2022-09-17 [1] CRAN (R 4.0.3)
#>
#> [1] /media/user/4B/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
#>
#> ──────────────────────────────────────────────────────────────────────────────
Traceback:
13: unique.default(x, nmax = nmax)
12: unique(x, nmax = nmax)
11: factor(x)
10: as.factor(f)
9: split.default(x = seq_len(nrow(x)), f = f, drop = drop, ...)
8: split(x = seq_len(nrow(x)), f = f, drop = drop, ...)
7: lapply(split(x = seq_len(nrow(x)), f = f, drop = drop, ...),
function(ind) x[ind, , drop = FALSE])
6: split.data.frame(., f = new_formula(NULL, enquo(grouping.var)),
drop = TRUE)
5: split(., f = new_formula(NULL, enquo(grouping.var)), drop = TRUE)
4: data %>% split(f = new_formula(NULL, enquo(grouping.var)), drop = TRUE)
3: .grouped_list(., {
{
grouping.var
}
})
2: data %<>% .grouped_list({
{
grouping.var
}
})
1: grouped_ggscatterstats(movies_long, budget, rating, grouping.var = genre)
Created on 2023-02-08 with reprex v2.0.2
Yes, I think this was the issue #Phil and #Behnam Hedayat. I tried reinstalling RStudio, I tried updating RStudio, I tried different versions of ggstatsplot to no avail. Finally, I decided to try to upgrade my version of Ubuntu, which did not work due to other issues, but at least it did seem to catch some new updates to the r-base and a few other libraries I could see, I think that solved the issue because the grouped_* commands are now working as they should.
During this upgrade process R updated to R v4.2.2 as #Phil and #Behnam Hedayat suggested. Thank you both for your help.
For anyone that might have this problem in the future, the commands I ran in terminal were the following and I found them here:
sudo apt update
sudo apt upgrade && sudo apt dist-upgrade
sudo update-manager -d

Multiple ggtext Markdown Annotations in ggplot2 Take Long Time to Render/Don't Render

I have been using Claus Wilke's great ggtext package for markdown annotations for a while now, and until now it's worked perfectly. In the course of using ggtext to make multiple text annotations (mix of bold face and regular text on multiple lines), either with the ggtext::geom_richtext() or ggtext::geom_textbox(), I found the more geom_richtext()s I added increased the rendering time to the point where it would just churn on end (I gave up after 45 minutes the last time).
Of course, creating and saving the ggplot object with all of the geom_richtext() and element_markdown()s took little time. But when I tried to view the plot or use ggsave to save as a png/jpeg it again churned forever (again, I gave up after 30 minutes).
I've included a sample reprex below.
My questions for ggtext and ggplot2 power users:
Is there an upper limit to the number of ggtext objects you can use in a ggplot2 plot? I'm not well-versed in grid and the underlying mechanics of ggplot.
Are there alternatives to ggtext to mix font weights in annotations in ggplot2? I already tried the plotmath route after seeing this from #aosmith on SO: html - Embolden substring of object passed through geom_text() - Stack Overflow. The problem? atop() only works on one line, not multiple lines of text.
FWIW, the full non-reprex version of my code (and the viz I'm trying to recreate in ggplot2) are at https://github.com/kpivert/wsj/tree/main/01_R/06_cpi_again.
Any recommendations you may have would be greatly appreciated.
Please let me know if you need further clarification or if the reprex doesn't work.
Thanks for your time and consideration.
Kurtis
require(ggthemes)
#> Loading required package: ggthemes
require(ggtext)
#> Loading required package: ggtext
require(tictoc)
#> Loading required package: tictoc
require(tidyverse)
#> Loading required package: tidyverse
df <- data.frame(
DATE = seq(as.Date("1913-01-01"), as.Date("2020-12-01"), "month")
) %>%
mutate(
var = rnorm(n = nrow(.), mean = 0, sd = 0.5)
)
# Years for X Axis Labels
yr_labs <- seq(as.Date("1915-01-01"), as.Date("2020-01-01"), by = "5 years") %>%
str_sub(start = 1, end = 4)
yr_labs <- case_when(
yr_labs == "1915" ~ "1915",
yr_labs == "2020" ~ "2020",
TRUE ~ str_c("'", str_sub(yr_labs, 3, 4))
)
tic()
ggplot(
df,
aes(
x = DATE,
y = var
)
) +
geom_line(
lwd = 0.2,
color = "blue"
) +
scale_x_continuous(
breaks = seq(as.Date("1915-01-01"), as.Date("2020-01-01"), by = "5 years"),
labels = yr_labs
) +
theme_tufte() +
theme(
panel.grid.major.y = element_line(size = .1),
axis.ticks.y = element_blank(),
axis.text.y = element_text(
vjust = - 0.8,
margin = margin(l = 20, r = -20)
),
plot.title = element_text(size = 16),
plot.subtitle = element_text(size = 10),
plot.caption = element_text(hjust = 0)
) +
labs(
x = "",
y = "",
caption = "Source: Randomness",
title = "Reprex Title",
subtitle = "Reprex Subtitle"
) +
# Annotations ----
# 1. WW I ----
geom_segment(
aes(
x = as.Date("1914-09-01"),
y = 1.25,
xend = as.Date("1918-11-01"),
yend = 1.25
),
lwd = 1
) +
geom_segment(
aes(
x = as.Date("1916-08-01"),
y = 1.25,
xend = as.Date("1916-08-01"),
yend = 1.28
),
linetype = "dotted"
) +
geom_richtext(
x = as.Date("1916-01-01"),
y = 1.28,
label = "<b>1914-18</b><br>World<br>War I",
fill = NA,
label.color = NA
)
toc()
#> 20.668 sec elapsed
Created on 2021-12-07 by the reprex package (v2.0.1)
Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.1.0 (2021-05-18)
#> os macOS Big Sur 10.16
#> system x86_64, darwin17.0
#> ui X11
#> language (EN)
#> collate en_US.UTF-8
#> ctype en_US.UTF-8
#> tz America/New_York
#> date 2021-12-07
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date lib source
#> assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.1.0)
#> backports 1.2.1 2020-12-09 [1] CRAN (R 4.1.0)
#> broom 0.7.9 2021-07-27 [1] CRAN (R 4.1.0)
#> cellranger 1.1.0 2016-07-27 [1] CRAN (R 4.1.0)
#> cli 3.0.1 2021-07-17 [1] CRAN (R 4.1.0)
#> colorspace 2.0-2 2021-06-24 [1] CRAN (R 4.1.0)
#> crayon 1.4.1 2021-02-08 [1] CRAN (R 4.1.0)
#> curl 4.3.2 2021-06-23 [1] CRAN (R 4.1.0)
#> DBI 1.1.1 2021-01-15 [1] CRAN (R 4.1.0)
#> dbplyr 2.1.1 2021-04-06 [1] CRAN (R 4.1.0)
#> digest 0.6.28 2021-09-23 [1] CRAN (R 4.1.0)
#> dplyr * 1.0.7 2021-06-18 [1] CRAN (R 4.1.0)
#> ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.1.0)
#> evaluate 0.14 2019-05-28 [1] CRAN (R 4.1.0)
#> fansi 0.5.0 2021-05-25 [1] CRAN (R 4.1.0)
#> farver 2.1.0 2021-02-28 [1] CRAN (R 4.1.0)
#> fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.1.0)
#> forcats * 0.5.1 2021-01-27 [1] CRAN (R 4.1.0)
#> fs 1.5.0 2020-07-31 [1] CRAN (R 4.1.0)
#> generics 0.1.0 2020-10-31 [1] CRAN (R 4.1.0)
#> ggplot2 * 3.3.5 2021-06-25 [1] CRAN (R 4.1.0)
#> ggtext * 0.1.1 2020-12-17 [1] CRAN (R 4.1.0)
#> ggthemes * 4.2.4 2021-01-20 [1] CRAN (R 4.1.0)
#> glue 1.4.2 2020-08-27 [1] CRAN (R 4.1.0)
#> gridtext 0.1.4 2020-12-10 [1] CRAN (R 4.1.0)
#> gtable 0.3.0 2019-03-25 [1] CRAN (R 4.1.0)
#> haven 2.4.3 2021-08-04 [1] CRAN (R 4.1.0)
#> highr 0.9 2021-04-16 [1] CRAN (R 4.1.0)
#> hms 1.1.0 2021-05-17 [1] CRAN (R 4.1.0)
#> htmltools 0.5.2 2021-08-25 [1] CRAN (R 4.1.0)
#> httr 1.4.2 2020-07-20 [1] CRAN (R 4.1.0)
#> jsonlite 1.7.2 2020-12-09 [1] CRAN (R 4.1.0)
#> knitr 1.36 2021-09-29 [1] CRAN (R 4.1.0)
#> labeling 0.4.2 2020-10-20 [1] CRAN (R 4.1.0)
#> lifecycle 1.0.1 2021-09-24 [1] CRAN (R 4.1.0)
#> lubridate 1.7.10 2021-02-26 [1] CRAN (R 4.1.0)
#> magrittr 2.0.1 2020-11-17 [1] CRAN (R 4.1.0)
#> markdown 1.1 2019-08-07 [1] CRAN (R 4.1.0)
#> mime 0.12 2021-09-28 [1] CRAN (R 4.1.0)
#> modelr 0.1.8 2020-05-19 [1] CRAN (R 4.1.0)
#> munsell 0.5.0 2018-06-12 [1] CRAN (R 4.1.0)
#> pillar 1.6.3 2021-09-26 [1] CRAN (R 4.1.0)
#> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.1.0)
#> purrr * 0.3.4 2020-04-17 [1] CRAN (R 4.1.0)
#> R6 2.5.1 2021-08-19 [1] CRAN (R 4.1.0)
#> Rcpp 1.0.7 2021-07-07 [1] CRAN (R 4.1.0)
#> readr * 2.0.1 2021-08-10 [1] CRAN (R 4.1.0)
#> readxl 1.3.1 2019-03-13 [1] CRAN (R 4.1.0)
#> reprex 2.0.1 2021-08-05 [1] CRAN (R 4.1.0)
#> rlang 0.4.11 2021-04-30 [1] CRAN (R 4.1.0)
#> rmarkdown 2.11 2021-09-14 [1] CRAN (R 4.1.0)
#> rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.1.0)
#> rvest 1.0.1 2021-07-26 [1] CRAN (R 4.1.0)
#> scales 1.1.1 2020-05-11 [1] CRAN (R 4.1.0)
#> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 4.1.0)
#> stringi 1.7.5 2021-10-04 [1] CRAN (R 4.1.0)
#> stringr * 1.4.0 2019-02-10 [1] CRAN (R 4.1.0)
#> styler 1.5.1 2021-07-13 [1] CRAN (R 4.1.0)
#> tibble * 3.1.5 2021-09-30 [1] CRAN (R 4.1.0)
#> tictoc * 1.0.1 2021-04-19 [1] CRAN (R 4.1.0)
#> tidyr * 1.1.3 2021-03-03 [1] CRAN (R 4.1.0)
#> tidyselect 1.1.1 2021-04-30 [1] CRAN (R 4.1.0)
#> tidyverse * 1.3.1 2021-04-15 [1] CRAN (R 4.1.0)
#> tzdb 0.1.2 2021-07-20 [1] CRAN (R 4.1.0)
#> utf8 1.2.2 2021-07-24 [1] CRAN (R 4.1.0)
#> vctrs 0.3.8 2021-04-29 [1] CRAN (R 4.1.0)
#> withr 2.4.2 2021-04-18 [1] CRAN (R 4.1.0)
#> xfun 0.26 2021-09-14 [1] CRAN (R 4.1.0)
#> xml2 1.3.2 2020-04-23 [1] CRAN (R 4.1.0)
#> yaml 2.2.1 2020-02-01 [1] CRAN (R 4.1.0)
#>
#> [1] /Library/Frameworks/R.framework/Versions/4.1/Resources/library
For the record, Jon Spring correctly noted the issue, which was the aesthetic mapping problem in the geom_segment() and geom_richtext() calls. In addition to his solution using annotate(), you can also pass a dataframe and use inherit.aes = FALSE so the text or segment isn't overplotted the same number of times as there are rows in the dataset. For example:
geom_richtext(
inherit.aes = FALSE,
data = tibble(
x = as.Date("1916-01-01"),
y = 1.28,
label = "<b>1914-18</b><br>World<br>War I"),
aes(
x = x,
y = y,
label = label),
fill = NA,
label.color = NA
)
Kara Woo's great presentation at the 2021 rstudio::global conference addressed this very issue: https://www.rstudio.com/resources/rstudioglobal-2021/always-look-on-the-bright-side-of-plots/.

How to split tectonic plate boundary polygon in a way to prevent line across the world map?

I am trying to plot tectonic plate boundaries on the world map. However, the tectonic plate's polygons seem to stretch across the world map (looking like they're at the opposite ends of the world, when they're actually side to side as the globe is round).
Is there a way I can split the plate where it wraps around?
Data:
library(tibble)
# polygon of tectonic plates
plate <- tibble(lat = c(-42.059, -41.910, -41.756, -41.657, -41.500, -41.188,
-40.807, -40.424, -40.087, -39.685, -39.230, -38.889,
-38.538, -38.205, -37.476, -36.793, -36.179, -35.542,
-35.022, -34.706, -34.485, -34.241, -33.846, -33.580,
-33.191, -32.696, -32.203, -31.957, -31.793, -31.452,
-31.037, -30.678, -30.322, -29.881, -29.469, -29.065,
-28.697, -28.264, -27.784, -27.318, -26.857, -26.437,
-26.025, -25.730, -25.426, -25.142, -24.836, -24.472,
-24.070, -23.750, -23.750, -23.853, -23.952, -24.029,
-24.105, -24.105, -24.242, -24.720, -25.197, -25.976,
-26.767, -27.377, -27.985, -28.693, -29.498, -29.792,
-30.355, -30.997, -31.333, -31.751, -32.347, -33.019,
-33.602, -34.246, -34.786, -35.161, -35.917, -36.461,
-37.102, -37.485, -37.885, -38.287, -38.674, -38.762,
-39.230, -40.046, -40.311, -40.598, -40.791, -40.979,
-41.157, -41.566, -41.757, -42.059, -42.059),
lon = c(175.503, 176.081 , 176.673, 177.123, 177.607,
178.015, 178.284, 178.566, 178.792, 178.950,
179.125, 179.215, 179.366, 179.569, 179.838,
-179.811, -179.371, -179.044, -178.641, -178.539,
-178.413, -178.294, -178.208, -177.981, -177.810,
-177.666, -177.649, -177.538, -177.301, -177.108,
-176.919, -176.690, -176.547, -176.339, -176.153,
-176.078, -175.995, -175.885, -175.785, -175.545,
-175.400, -175.423, -175.415, -175.382, -175.297,
-175.261, -175.229, -175.209, -175.102, -174.985,
-174.985, -175.691, -176.356, -176.887, -177.419,
-177.419, -177.448, -177.552, -177.657, -177.793,
-178.017, -178.248, -178.482, -178.713, -178.966,
-179.074, -179.226, -179.393, -179.515, -179.740,
179.980, 179.657, 179.345, 178.996, 178.681,
178.403, 177.890, 177.507, 177.049, 176.770,
176.509, 176.241, 175.995, 175.932, 175.609,
176.074, 175.868, 175.537, 175.324, 175.012,
174.632, 174.763, 174.945, 175.503, 175.503)
)
Code:
library(ggplot2)
library(dplyr)
# world data to map world map
world <- map_data("world")
# world map with tectonic plate in green
world %>%
ggplot() +
geom_map(map = world,
aes(x = long, y = lat,
map_id = region)) +
geom_polygon(data = plate,
aes(x = lon,
y = lat),
fill = NA,
colour = "dark green")
#> Warning: Ignoring unknown aesthetics: x, y
Created on 2020-08-26 by the reprex package (v0.3.0)
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.0.2 (2020-06-22)
#> os macOS Catalina 10.15.6
#> system x86_64, darwin17.0
#> ui X11
#> language (EN)
#> collate en_AU.UTF-8
#> ctype en_AU.UTF-8
#> tz Australia/Melbourne
#> date 2020-08-26
#>
#> ─ 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)
#> blob 1.2.1 2020-01-20 [1] CRAN (R 4.0.2)
#> broom 0.7.0 2020-07-09 [1] CRAN (R 4.0.2)
#> callr 3.4.3 2020-03-28 [1] CRAN (R 4.0.2)
#> cellranger 1.1.0 2016-07-27 [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.1)
#> DBI 1.1.0 2019-12-15 [1] CRAN (R 4.0.2)
#> dbplyr 1.4.4 2020-05-27 [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)
#> dplyr * 1.0.1 2020-07-31 [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.1)
#> fansi 0.4.1 2020-01-08 [1] CRAN (R 4.0.2)
#> farver 2.0.3 2020-01-16 [1] CRAN (R 4.0.2)
#> forcats * 0.5.0 2020-03-01 [1] CRAN (R 4.0.2)
#> fs 1.5.0 2020-07-31 [1] CRAN (R 4.0.2)
#> generics 0.0.2 2018-11-29 [1] CRAN (R 4.0.2)
#> ggplot2 * 3.3.2 2020-06-19 [1] CRAN (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] CRAN (R 4.0.2)
#> haven 2.3.1 2020-06-01 [1] CRAN (R 4.0.2)
#> highr 0.8 2019-03-20 [1] CRAN (R 4.0.2)
#> hms 0.5.3 2020-01-08 [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)
#> jsonlite 1.7.0 2020-06-25 [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)
#> lubridate 1.7.9 2020-06-08 [1] CRAN (R 4.0.2)
#> magrittr 1.5 2014-11-22 [1] CRAN (R 4.0.2)
#> maps 3.3.0 2018-04-03 [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)
#> modelr 0.1.8 2020-05-19 [1] CRAN (R 4.0.2)
#> munsell 0.5.0 2018-06-12 [1] CRAN (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)
#> purrr * 0.3.4 2020-04-17 [1] CRAN (R 4.0.2)
#> R6 2.4.1 2019-11-12 [1] CRAN (R 4.0.2)
#> Rcpp 1.0.5 2020-07-06 [1] CRAN (R 4.0.2)
#> readr * 1.3.1 2018-12-21 [1] CRAN (R 4.0.2)
#> readxl 1.3.1 2019-03-13 [1] CRAN (R 4.0.2)
#> remotes 2.2.0 2020-07-21 [1] CRAN (R 4.0.2)
#> reprex 0.3.0 2019-05-16 [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] CRAN (R 4.0.2)
#> rprojroot 1.3-2 2018-01-03 [1] CRAN (R 4.0.2)
#> rvest 0.3.6 2020-07-25 [1] CRAN (R 4.0.2)
#> scales 1.1.1 2020-05-11 [1] CRAN (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)
#> tidyr * 1.1.1 2020-07-31 [1] CRAN (R 4.0.2)
#> tidyselect 1.1.0 2020-05-11 [1] CRAN (R 4.0.2)
#> tidyverse * 1.3.0 2019-11-21 [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] /Library/Frameworks/R.framework/Versions/4.0/Resources/library
To perform the split, you can convert your data frame to a sf object & take advantage of the st_wrap_dateline function:
library(sf)
# convert to sf object & split into 2 polygons
plate.sf <- st_polygon(x = list(as.matrix(plate %>% select(lon, lat)))) %>%
st_wrap_dateline()
# plot using geom_sf
world %>%
ggplot() +
geom_map(map = world,
aes(x = long, y = lat,
map_id = region)) +
geom_sf(data = plate.sf, colour = "dark green")
If you want to stick with geom_polygon instead of geom_sf, convert the polygons back to dataframe:
plate2 <- lapply(seq_along(plate.sf),
function(i) as.data.frame(plate.sf[[i]][[1]]) %>%
rename(lon = V1, lat = V2) %>%
mutate(group = i)) %>%
data.table::rbindlist()
world %>%
ggplot() +
geom_map(map = world,
aes(x = long, y = lat,
map_id = region)) +
geom_polygon(data = plate2,
aes(x = lon, y = lat, group = group),
fill = NA, colour = "dark green")
Edit: expanded answer for dataframe with multiple plates
# mock up data frame with 2 distinct plates (mirror image of each other)
plates <- rbind(plate %>% mutate(plate = 1),
plate %>% mutate(lat = -lat, plate = 2)) %>%
select(plate, lat, lon)
# process data for geom_polygon approach
plates2 <- plates %>%
# split into separate data frame for each plate
split(.$plate) %>%
# convert to polygon & split along date line (as before)
lapply(function(d) d %>% select(lon, lat) %>%
as.matrix() %>%
list() %>%
st_polygon() %>%
st_wrap_dateline()) %>%
# convert each plate back to data frame (as before)
lapply(function(d) lapply(seq_along(d),
function(i) as.data.frame(d[[i]][[1]]) %>%
rename(lon = V1, lat = V2) %>%
mutate(group = i)) %>%
data.table::rbindlist()) %>%
# combine into one overall data frame
bind_rows(.id = "plate") %>%
mutate(group = paste(plate, group, sep = "."))
# result
world %>%
ggplot() +
geom_map(map = world,
aes(x = long, y = lat,
map_id = region)) +
geom_polygon(data = plates2,
aes(x = lon, y = lat, group = group),
fill = NA, colour = "dark green")

R: ggplot2 plot with ggupset and hrbrthemes::theme_upsum(): Superfluous "at" appears at x-axis label

I am using hrbrthemes::theme_ipsum() with most of my plots, but now I'm encountering odd behaviour while using ggupset: An extra "at" above the x-axis label that I can neither find the origin of nor can get rid of.
If anyone could try to explain what's going on here (and how to get rid of it), that'd be great.
Note that I tried both the current CRAN and GitHub versions of hrbrthemes.
Demonstration:
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 from ggupset's README
p <- tidy_movies %>%
distinct(title, year, length, .keep_all = TRUE) %>%
head(100) %>% # smaller dataset for faster(ish) 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() the easy way
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, now with theme_ipsum. Notice the x-axis on the bottom right.
p
#> Warning: Removed 30 rows containing non-finite values (stat_count).
I can't find any label set to "at". at what?
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
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
Created on 2020-03-24 by the reprex package (v0.3.0)
Update 2020-03-24: The author of ggupset has responded on GitHub and is taking a look.
The issue was caused by ggupset, and has since been fixed.
If anyone else has encountered this, you can use the current development version: remotes::install_github("const-ae/ggupset"), or wait for the CRAN release in the near future.

Greek letters in R expressions result in missing glyph

When I use Greek letters in a plot label in R on Fedora 31, the expression will not be properly rendered. Instead of the Greek letter, a missing glyph box appears in the label. The same code works properly on rstudio.cloud. The same behavior can also be observed in ggplot. See the reprex below for an example.
As I understand it, R takes an OS default font for text in plots. This seems to be Liberation Sans in my case. I do not get the problem here, as Liberation has glyphs for the Greek alphabet.
Any help would be appreciated.
Edit
Further investigation resulted in some weird things. I ran the code from terminal and the same thing happens. But within RStudio, when I execute x11() before running plot, then the output is rendered properly in the x11 window.
The strange thing about this is, that x11 appears to be the default graphics device when running the code from the terminal. However, even if I run x11() beforehand in the terminal, it returns a plot with the missing glyph box.
After learning that this has something to do with the graphics device, I tried various graphics devices with ggsave(). With all the formats I tried, the expression was rendered properly.
What is not yet clear to me is the source of the problem. Is this a bug in the R binary from dnf? Or where could the issue lie? I do remember that it work with Fedora 30 a couple of months ago.
plot(Sepal.Length ~ Sepal.Width,
iris,
xlab = expression(beta))
Created on 2020-03-06 by the reprex package (v0.3.0)
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 3.6.2 (2019-12-12)
#> os Fedora 31 (Workstation Edition)
#> system x86_64, linux-gnu
#> ui X11
#> language (EN)
#> collate en_US.UTF-8
#> ctype en_US.UTF-8
#> tz Europe/Berlin
#> date 2020-03-06
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date lib source
#> assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.6.1)
#> backports 1.1.5 2019-10-02 [1] CRAN (R 3.6.1)
#> callr 3.4.2 2020-02-12 [1] CRAN (R 3.6.2)
#> cli 2.0.1 2020-01-08 [1] CRAN (R 3.6.2)
#> crayon 1.3.4 2017-09-16 [1] CRAN (R 3.6.1)
#> curl 4.3 2019-12-02 [1] CRAN (R 3.6.1)
#> desc 1.2.0 2018-05-01 [1] CRAN (R 3.6.2)
#> devtools 2.2.2 2020-02-17 [1] CRAN (R 3.6.2)
#> digest 0.6.25 2020-02-23 [1] CRAN (R 3.6.2)
#> ellipsis 0.3.0 2019-09-20 [1] CRAN (R 3.6.1)
#> evaluate 0.14 2019-05-28 [1] CRAN (R 3.6.1)
#> fansi 0.4.1 2020-01-08 [1] CRAN (R 3.6.2)
#> fs 1.3.1 2019-05-06 [1] CRAN (R 3.6.1)
#> glue 1.3.1 2019-03-12 [1] CRAN (R 3.6.1)
#> highr 0.8 2019-03-20 [1] CRAN (R 3.6.1)
#> htmltools 0.4.0 2019-10-04 [1] CRAN (R 3.6.1)
#> httr 1.4.1 2019-08-05 [1] CRAN (R 3.6.1)
#> knitr 1.28 2020-02-06 [1] CRAN (R 3.6.2)
#> magrittr 1.5 2014-11-22 [1] CRAN (R 3.6.1)
#> memoise 1.1.0 2017-04-21 [1] CRAN (R 3.6.2)
#> mime 0.9 2020-02-04 [1] CRAN (R 3.6.2)
#> pkgbuild 1.0.6 2019-10-09 [1] CRAN (R 3.6.2)
#> pkgload 1.0.2 2018-10-29 [1] CRAN (R 3.6.2)
#> prettyunits 1.1.1 2020-01-24 [1] CRAN (R 3.6.2)
#> processx 3.4.2 2020-02-09 [1] CRAN (R 3.6.2)
#> ps 1.3.2 2020-02-13 [1] CRAN (R 3.6.2)
#> R6 2.4.1 2019-11-12 [1] CRAN (R 3.6.1)
#> Rcpp 1.0.3 2019-11-08 [1] CRAN (R 3.6.1)
#> remotes 2.1.1 2020-02-15 [1] CRAN (R 3.6.2)
#> rlang 0.4.4 2020-01-28 [1] CRAN (R 3.6.2)
#> rmarkdown 2.1 2020-01-20 [1] CRAN (R 3.6.2)
#> rprojroot 1.3-2 2018-01-03 [1] CRAN (R 3.6.2)
#> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.6.2)
#> stringi 1.4.6 2020-02-17 [1] CRAN (R 3.6.2)
#> stringr 1.4.0 2019-02-10 [1] CRAN (R 3.6.1)
#> testthat 2.3.1 2019-12-01 [1] CRAN (R 3.6.2)
#> usethis 1.5.1 2019-07-04 [1] CRAN (R 3.6.2)
#> withr 2.1.2 2018-03-15 [1] CRAN (R 3.6.1)
#> xfun 0.12 2020-01-13 [1] CRAN (R 3.6.2)
#> xml2 1.2.2 2019-08-09 [1] CRAN (R 3.6.1)
#> yaml 2.2.1 2020-02-01 [1] CRAN (R 3.6.2)
#>
#> [1] /home/steffen/R/x86_64-redhat-linux-gnu-library/3.6
#> [2] /usr/lib64/R/library
#> [3] /usr/share/R/library

Resources