How to plot GeoTIFF using tmap in R? - r

A simple plotRGB leads to the original image while plotting with tmap returns only a blue-shaded image. What am I doing wrong?
original image
blue-shaded image
Code snippet:
library(raster)
library(tmap)
library(rnaturalearth)
ne_download(scale = 50, type = 'HYP_50M_SR_W', category = 'raster', destdir = getwd())
rst <- brick("HYP_50M_SR_W/HYP_50M_SR_W.tif")
plotRGB(rst) # works
tmap_mode("plot")
tm_shape(rst) + tm_rgb() # does not work
Using: R version 3.5.1, RStudio 1.1.456, tmap 2.1-1, raster 2.6-7, rnaturalearth 0.1.0

It might be working now, note the warning though:
library(raster)
#> Loading required package: sp
library(tmap)
#> Warning: package 'tmap' was built under R version 3.5.2
library(rnaturalearth)
#> Warning: package 'rnaturalearth' was built under R version 3.5.2
ne_download(scale = 50, type = 'HYP_50M_SR_W', category = 'raster', destdir = getwd())
rst <- brick("HYP_50M_SR_W/HYP_50M_SR_W.tif")
plotRGB(rst)
tm_shape(rst) + tm_rgb()
#> Raster object has 58320000 (5400 by 10800) cells, which is larger than 1e+07, the maximum size determined by the option max.raster. Therefore, the raster will be shown at a decreased resolution of 1e+07 cells. Set tmap_options(max.raster = c(plot = 58320000, view = 58320000)) to show the whole raster.
#> Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3
Created on 2019-01-30 by the reprex package (v0.2.1)
devtools::session_info()
#> - Session info ----------------------------------------------------------
#> setting value
#> version R version 3.5.1 (2018-07-02)
#> os Windows 7 x64 SP 1
#> system x86_64, mingw32
#> ui RTerm
#> language (EN)
#> collate English_United States.1252
#> ctype English_United States.1252
#> tz Europe/Berlin
#> date 2019-01-30
#>
#> - Packages --------------------------------------------------------------
#> package * version date lib source
#> assertthat 0.2.0 2017-04-11 [1] CRAN (R 3.5.1)
#> backports 1.1.2 2017-12-13 [1] CRAN (R 3.5.0)
#> base64enc 0.1-3 2015-07-28 [1] CRAN (R 3.5.0)
#> callr 3.0.0 2018-08-24 [1] CRAN (R 3.5.1)
#> class 7.3-14 2015-08-30 [2] CRAN (R 3.5.1)
#> classInt 0.2-3 2018-04-16 [1] CRAN (R 3.5.1)
#> cli 1.0.1 2018-09-25 [1] CRAN (R 3.5.1)
#> codetools 0.2-15 2016-10-05 [2] CRAN (R 3.5.1)
#> colorspace 1.3-2 2016-12-14 [1] CRAN (R 3.5.1)
#> crayon 1.3.4 2017-09-16 [1] CRAN (R 3.5.1)
#> crosstalk 1.0.0 2016-12-21 [1] CRAN (R 3.5.1)
#> curl 3.2 2018-03-28 [1] CRAN (R 3.5.1)
#> DBI 1.0.0 2018-05-02 [1] CRAN (R 3.5.1)
#> desc 1.2.0 2018-05-01 [1] CRAN (R 3.5.1)
#> devtools 2.0.1 2018-10-26 [1] CRAN (R 3.5.1)
#> dichromat 2.0-0 2013-01-24 [1] CRAN (R 3.5.0)
#> digest 0.6.18 2018-10-10 [1] CRAN (R 3.5.1)
#> e1071 1.7-0 2018-07-28 [1] CRAN (R 3.5.1)
#> evaluate 0.12 2018-10-09 [1] CRAN (R 3.5.1)
#> fs 1.2.6 2018-08-23 [1] CRAN (R 3.5.1)
#> glue 1.3.0 2018-07-17 [1] CRAN (R 3.5.1)
#> htmltools 0.3.6 2017-04-28 [1] CRAN (R 3.5.1)
#> htmlwidgets 1.3 2018-09-30 [1] CRAN (R 3.5.1)
#> httpuv 1.4.5 2018-07-19 [1] CRAN (R 3.5.1)
#> httr 1.3.1 2017-08-20 [1] CRAN (R 3.5.1)
#> KernSmooth 2.23-15 2015-06-29 [2] CRAN (R 3.5.1)
#> knitr 1.20 2018-02-20 [1] CRAN (R 3.5.1)
#> later 0.7.5 2018-09-18 [1] CRAN (R 3.5.1)
#> lattice 0.20-35 2017-03-25 [2] CRAN (R 3.5.1)
#> leaflet 2.0.2 2018-08-27 [1] CRAN (R 3.5.1)
#> lwgeom 0.1-5 2018-12-07 [1] CRAN (R 3.5.1)
#> magrittr 1.5 2014-11-22 [1] CRAN (R 3.5.1)
#> mapview 2.6.0 2018-09-16 [1] CRAN (R 3.5.1)
#> memoise 1.1.0 2017-04-21 [1] CRAN (R 3.5.1)
#> mime 0.6 2018-10-05 [1] CRAN (R 3.5.1)
#> munsell 0.5.0 2018-06-12 [1] CRAN (R 3.5.1)
#> pkgbuild 1.0.2 2018-10-16 [1] CRAN (R 3.5.1)
#> pkgload 1.0.2 2018-10-29 [1] CRAN (R 3.5.1)
#> png 0.1-7 2013-12-03 [1] CRAN (R 3.5.0)
#> prettyunits 1.0.2 2015-07-13 [1] CRAN (R 3.5.1)
#> processx 3.2.0 2018-08-16 [1] CRAN (R 3.5.1)
#> promises 1.0.1 2018-04-13 [1] CRAN (R 3.5.1)
#> ps 1.2.1 2018-11-06 [1] CRAN (R 3.5.1)
#> R6 2.3.0 2018-10-04 [1] CRAN (R 3.5.1)
#> raster * 2.8-4 2018-11-03 [1] CRAN (R 3.5.1)
#> RColorBrewer 1.1-2 2014-12-07 [1] CRAN (R 3.5.0)
#> Rcpp 1.0.0 2018-11-07 [1] CRAN (R 3.5.1)
#> remotes 2.0.2 2018-10-30 [1] CRAN (R 3.5.1)
#> rgdal 1.3-6 2018-10-16 [1] CRAN (R 3.5.1)
#> rgeos 0.4-2 2018-11-08 [1] CRAN (R 3.5.1)
#> rlang 0.3.0.1 2018-10-25 [1] CRAN (R 3.5.1)
#> rmarkdown 1.10 2018-06-11 [1] CRAN (R 3.5.1)
#> rnaturalearth * 0.1.0 2017-03-21 [1] CRAN (R 3.5.2)
#> rprojroot 1.3-2 2018-01-03 [1] CRAN (R 3.5.1)
#> satellite 1.0.1 2017-10-18 [1] CRAN (R 3.5.1)
#> scales 1.0.0 2018-08-09 [1] CRAN (R 3.5.1)
#> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.5.1)
#> sf * 0.7-1 2018-10-24 [1] CRAN (R 3.5.1)
#> shiny 1.2.0 2018-11-02 [1] CRAN (R 3.5.1)
#> sp * 1.3-1 2018-06-05 [1] CRAN (R 3.5.1)
#> spData 0.2.9.4 2018-09-15 [1] CRAN (R 3.5.1)
#> stringi 1.2.4 2018-07-20 [1] CRAN (R 3.5.1)
#> stringr 1.3.1 2018-05-10 [1] CRAN (R 3.5.1)
#> tmap * 2.2 2019-01-05 [1] CRAN (R 3.5.2)
#> tmaptools 2.0-1 2018-08-07 [1] CRAN (R 3.5.1)
#> units 0.6-1 2018-09-21 [1] CRAN (R 3.5.1)
#> usethis 1.4.0 2018-08-14 [1] CRAN (R 3.5.1)
#> viridisLite 0.3.0 2018-02-01 [1] CRAN (R 3.5.1)
#> webshot 0.5.1 2018-09-28 [1] CRAN (R 3.5.1)
#> withr 2.1.2 2018-03-15 [1] CRAN (R 3.5.1)
#> XML 3.98-1.16 2018-08-19 [1] CRAN (R 3.5.1)
#> xml2 1.2.0 2018-01-24 [1] CRAN (R 3.5.1)
#> xtable 1.8-3 2018-08-29 [1] CRAN (R 3.5.1)
#> yaml 2.2.0 2018-07-25 [1] CRAN (R 3.5.1)

Related

`Brolgar` facet_sample function example confusing error?

I get this error in my own code and when I run the documentation example for facet_sample() (shown below) using the brolgar package on its own built in "heights" data. Nothing I've Googled is similar, and appreciate any guidance on what is causing this, and have included SystemInfo below in case it may be caused by something in my installation.
library(brolgar)
#> Warning: package 'brolgar' was built under R version 4.1.2
library(ggplot2)
ggplot(heights,
aes(x = year,
y = height_cm,
group = country)) +
geom_line() +
facet_sample()
#> Error in f(...): 3 arguments passed to .Internal(is.unsorted) which requires 2
Created on 2021-12-19 by the reprex package (v2.0.1)
Session info
sessioninfo::session_info()
#> - Session info ---------------------------------------------------------------
#> setting value
#> version R version 4.1.1 (2021-08-10)
#> os Windows 10 x64 (build 19043)
#> system x86_64, mingw32
#> ui RTerm
#> language (EN)
#> collate English_United States.1252
#> ctype English_United States.1252
#> tz America/New_York
#> date 2021-12-19
#> pandoc 2.14.0.3 # C:/Program Files/RStudio/bin/pandoc/ (via rmarkdown)
#>
#> - Packages -------------------------------------------------------------------
#> package * version date (UTC) lib source
#> anytime 0.3.9 2020-08-27 [1] CRAN (R 4.1.2)
#> assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.1.1)
#> brolgar * 0.1.2 2021-08-25 [1] CRAN (R 4.1.2)
#> cli 3.1.0 2021-10-27 [1] CRAN (R 4.1.1)
#> colorspace 2.0-2 2021-06-24 [1] CRAN (R 4.1.1)
#> crayon 1.4.2 2021-10-29 [1] CRAN (R 4.1.1)
#> curl 4.3.2 2021-06-23 [1] CRAN (R 4.1.1)
#> DBI 1.1.1 2021-01-15 [1] CRAN (R 4.1.1)
#> digest 0.6.29 2021-12-01 [1] CRAN (R 4.1.1)
#> distributional 0.2.2 2021-02-02 [1] CRAN (R 4.1.2)
#> dplyr 1.0.7 2021-06-18 [1] CRAN (R 4.1.1)
#> ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.1.1)
#> evaluate 0.14 2019-05-28 [1] CRAN (R 4.1.1)
#> fabletools 0.3.2 2021-11-29 [1] CRAN (R 4.1.2)
#> fansi 0.5.0 2021-05-25 [1] CRAN (R 4.1.1)
#> farver 2.1.0 2021-02-28 [1] CRAN (R 4.1.1)
#> fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.1.1)
#> fs 1.5.2 2021-12-08 [1] CRAN (R 4.1.1)
#> generics 0.1.1 2021-10-25 [1] CRAN (R 4.1.1)
#> ggplot2 * 3.3.5 2021-06-25 [1] CRAN (R 4.1.1)
#> glue 1.5.1 2021-11-30 [1] CRAN (R 4.1.2)
#> gtable 0.3.0 2019-03-25 [1] CRAN (R 4.1.1)
#> highr 0.9 2021-04-16 [1] CRAN (R 4.1.1)
#> htmltools 0.5.2 2021-08-25 [1] CRAN (R 4.1.1)
#> httr 1.4.2 2020-07-20 [1] CRAN (R 4.1.1)
#> knitr 1.37 2021-12-16 [1] CRAN (R 4.1.1)
#> lifecycle 1.0.1 2021-09-24 [1] CRAN (R 4.1.1)
#> lubridate 1.8.0 2021-10-07 [1] CRAN (R 4.1.1)
#> magrittr 2.0.1 2020-11-17 [1] CRAN (R 4.1.1)
#> mime 0.12 2021-09-28 [1] CRAN (R 4.1.1)
#> munsell 0.5.0 2018-06-12 [1] CRAN (R 4.1.1)
#> pillar 1.6.4 2021-10-18 [1] CRAN (R 4.1.1)
#> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.1.1)
#> purrr 0.3.4 2020-04-17 [1] CRAN (R 4.1.1)
#> R6 2.5.1 2021-08-19 [1] CRAN (R 4.1.1)
#> Rcpp 1.0.7 2021-07-07 [1] CRAN (R 4.1.1)
#> reprex 2.0.1 2021-08-05 [1] CRAN (R 4.1.1)
#> rlang 0.4.12 2021-10-18 [1] CRAN (R 4.1.1)
#> rmarkdown 2.11 2021-09-14 [1] CRAN (R 4.1.1)
#> rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.1.1)
#> scales 1.1.1 2020-05-11 [1] CRAN (R 4.1.1)
#> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.1.1)
#> stringi 1.7.6 2021-11-29 [1] CRAN (R 4.1.1)
#> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.1.1)
#> tibble 3.1.6 2021-11-07 [1] CRAN (R 4.1.1)
#> tidyr 1.1.4 2021-09-27 [1] CRAN (R 4.1.1)
#> tidyselect 1.1.1 2021-04-30 [1] CRAN (R 4.1.1)
#> tsibble 1.1.1 2021-12-03 [1] CRAN (R 4.1.2)
#> utf8 1.2.2 2021-07-24 [1] CRAN (R 4.1.1)
#> vctrs 0.3.8 2021-04-29 [1] CRAN (R 4.1.1)
#> withr 2.4.3 2021-11-30 [1] CRAN (R 4.1.1)
#> xfun 0.28 2021-11-04 [1] CRAN (R 4.1.2)
#> xml2 1.3.3 2021-11-30 [1] CRAN (R 4.1.1)
#> yaml 2.2.1 2020-02-01 [1] CRAN (R 4.1.1)
#>
#> [1] C:/Users/dlucey/OneDrive - South Bronx Classical Charter School/Documents/R/R-4.1.1/library
#>
#> ------------------------------------------------------------------------------

ggplot2 png file without background

Since a few months, ggplot2 started to save png files with a transparent background. The code output in Rstudio and when saved as pdf looks great. It happens mainly with the use of themes when I omit the gray panel background. I tested it on my macbook with "Preview" and on a Windows Computer with the "foto viewer" there.
library(ggplot2)
library(dplyr)
mtcars %>%
ggplot(aes(x = mpg, y = cyl)) +
geom_point() +
theme_minimal()
This is how the file should look (with a white background):
ggsave("test.png", dpi = 300)
#> Saving 7 x 5 in image
ggsave("test.pdf")
#> Saving 5.54 x 4.56 in image
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.1.1 (2021-08-10)
#> os macOS Big Sur 10.16
#> system x86_64, darwin17.0
#> ui X11
#> language (EN)
#> collate de_CH.UTF-8
#> ctype de_CH.UTF-8
#> tz Europe/Zurich
#> date 2021-11-11
#>
#> ─ 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)
#> cachem 1.0.6 2021-08-19 [1] CRAN (R 4.1.0)
#> callr 3.7.0 2021-04-20 [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)
#> DBI 1.1.1 2021-01-15 [1] CRAN (R 4.1.0)
#> desc 1.3.0 2021-03-05 [1] CRAN (R 4.1.0)
#> devtools 2.4.2 2021-06-07 [1] CRAN (R 4.1.0)
#> digest 0.6.27 2020-10-24 [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)
#> 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)
#> glue 1.4.2 2020-08-27 [1] CRAN (R 4.1.0)
#> gtable 0.3.0 2019-03-25 [1] CRAN (R 4.1.0)
#> highr 0.9 2021-04-16 [1] CRAN (R 4.1.0)
#> htmltools 0.5.2 2021-08-25 [1] CRAN (R 4.1.0)
#> knitr 1.34 2021-09-09 [1] CRAN (R 4.1.0)
#> labeling 0.4.2 2020-10-20 [1] CRAN (R 4.1.0)
#> lifecycle 1.0.0 2021-02-15 [1] CRAN (R 4.1.0)
#> magrittr 2.0.1 2020-11-17 [1] CRAN (R 4.1.0)
#> memoise 2.0.0 2021-01-26 [1] CRAN (R 4.1.0)
#> munsell 0.5.0 2018-06-12 [1] CRAN (R 4.1.0)
#> pillar 1.6.2 2021-07-29 [1] CRAN (R 4.1.0)
#> pkgbuild 1.2.0 2020-12-15 [1] CRAN (R 4.1.0)
#> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.1.0)
#> pkgload 1.2.2 2021-09-11 [1] CRAN (R 4.1.0)
#> prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.1.0)
#> processx 3.5.2 2021-04-30 [1] CRAN (R 4.1.0)
#> ps 1.6.0 2021-02-28 [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)
#> ragg 1.1.3 2021-06-09 [1] CRAN (R 4.1.0)
#> remotes 2.4.0 2021-06-02 [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)
#> rprojroot 2.0.2 2020-11-15 [1] CRAN (R 4.1.0)
#> rstudioapi 0.13 2020-11-12 [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.4 2021-08-25 [1] CRAN (R 4.1.0)
#> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.1.0)
#> styler 1.6.1 2021-09-17 [1] CRAN (R 4.1.0)
#> systemfonts 1.0.2 2021-05-11 [1] CRAN (R 4.1.0)
#> testthat 3.0.4 2021-07-01 [1] CRAN (R 4.1.0)
#> textshaping 0.3.5 2021-06-09 [1] CRAN (R 4.1.0)
#> tibble 3.1.4 2021-08-25 [1] CRAN (R 4.1.0)
#> tidyselect 1.1.1 2021-04-30 [1] CRAN (R 4.1.0)
#> usethis 2.0.1 2021-02-10 [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)
#> yaml 2.2.1 2020-02-01 [1] CRAN (R 4.1.0)
#>
#> [1] /Library/Frameworks/R.framework/Versions/4.1/Resources/library
Created on 2021-11-11 by the reprex package (v2.0.1)
This is how the files look side-by-side:
I have tested all graphic devices in the "backend" tab under prefences/general/graphics and I also tested everything in R (not R Studio) with the same result.
set the bg argument to "white", e.g.
ggsave("test.png", dpi = 300, bg = "white")
This argument will be passed to grDevices::png via the ... argument. bg controls the background of the device.

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.

In R package Xaringan, unable to render with infinite moon reader

Using the R package xaringan, I was trying to create a new presentation in RStudio. I wanted to use the very useful feature inifinite moon reader to get live preview of my tweaking of the presentation. While worked nicely previously, currently for me the presentation is not rendering anymore. What changed in between is probably regular updates in software, operating system and R packages.
Now whenever I press the infinite moon reader addin in RStudio, it spits the error as shown in the image. But when I press the knit to moonreader button in RStudio it renders the document just fine but there is not live preview.
I tried to run R in a console and then used the inf_mr() function to render the document. It spits out the same error. But rmarkdown::render() function works just fine but again with no live preview. I searched for this error but I do not seem to find anything as such related to xaringan package in R. Then I ran a more generalized search and found that the error statement most often comes in the case of XML parsing. I updated the XML and XML2 packages in R but with no luck. Then I updated and upgraded my Arch Linux also to no avail.
Created on 2019-08-13 by the reprex package (v0.3.0)
devtools::session_info()
#> ─ Session info ──────────────────────────────────────────────────────────
#> setting value
#> version R version 3.6.1 (2019-07-05)
#> os Arch Linux
#> system x86_64, linux-gnu
#> ui X11
#> language (EN)
#> collate en_US.UTF-8
#> ctype en_US.UTF-8
#> tz Asia/Dhaka
#> date 2019-08-13
#>
#> ─ Packages ──────────────────────────────────────────────────────────────
#> package * version date lib source
#> assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.5.3)
#> backports 1.1.4 2019-04-10 [1] CRAN (R 3.5.3)
#> callr 2.0.4 2018-05-15 [1] CRAN (R 3.5.1)
#> cli 1.1.0 2019-03-19 [1] CRAN (R 3.5.3)
#> crayon 1.3.4 2017-09-16 [1] CRAN (R 3.5.1)
#> curl 3.3 2019-01-10 [1] CRAN (R 3.5.3)
#> desc 1.2.0 2018-05-01 [1] CRAN (R 3.5.3)
#> devtools 2.0.2 2019-04-08 [1] CRAN (R 3.5.3)
#> digest 0.6.20 2019-07-04 [1] CRAN (R 3.6.0)
#> evaluate 0.14 2019-05-28 [1] CRAN (R 3.6.0)
#> fs 1.3.1 2019-05-06 [1] CRAN (R 3.5.3)
#> glue 1.3.1 2019-03-12 [1] CRAN (R 3.5.3)
#> highr 0.8 2019-03-20 [1] CRAN (R 3.6.0)
#> htmltools 0.3.6 2017-04-28 [1] CRAN (R 3.5.1)
#> httr 1.4.0 2018-12-11 [1] CRAN (R 3.5.3)
#> knitr 1.24 2019-08-08 [1] CRAN (R 3.6.0)
#> magrittr 1.5 2014-11-22 [1] CRAN (R 3.5.1)
#> memoise 1.1.0 2017-04-21 [1] CRAN (R 3.5.1)
#> mime 0.7 2019-06-11 [1] CRAN (R 3.6.0)
#> nvimcom * 0.9-75 2019-08-13 [1] local
#> pkgbuild 1.0.3 2019-03-20 [1] CRAN (R 3.5.3)
#> pkgload 1.0.2 2018-10-29 [1] CRAN (R 3.5.3)
#> png 0.1-7 2013-12-03 [1] CRAN (R 3.5.3)
#> prettyunits 1.0.2 2015-07-13 [1] CRAN (R 3.5.3)
#> processx 3.2.0 2018-08-16 [1] CRAN (R 3.5.1)
#> ps 1.1.0 2018-08-10 [1] CRAN (R 3.5.1)
#> R6 2.4.0 2019-02-14 [1] CRAN (R 3.5.3)
#> Rcpp 1.0.2 2019-07-25 [1] CRAN (R 3.6.0)
#> remotes 2.0.4 2019-04-10 [1] CRAN (R 3.5.3)
#> rlang 0.4.0 2019-06-25 [1] CRAN (R 3.6.0)
#> rmarkdown 1.14 2019-07-12 [1] CRAN (R 3.6.0)
#> rprojroot 1.3-2 2018-01-03 [1] CRAN (R 3.5.1)
#> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.5.3)
#> stringi 1.4.3 2019-03-12 [1] CRAN (R 3.6.0)
#> stringr 1.4.0 2019-02-10 [1] CRAN (R 3.6.0)
#> testthat 2.1.1 2019-04-23 [1] CRAN (R 3.6.0)
#> usethis 1.5.1 2019-07-04 [1] CRAN (R 3.6.0)
#> withr 2.1.2 2018-03-15 [1] CRAN (R 3.5.1)
#> xfun 0.8 2019-06-25 [1] CRAN (R 3.6.0)
#> xml2 1.2.2 2019-08-09 [1] CRAN (R 3.6.0)
#> yaml 2.2.0 2018-07-25 [1] CRAN (R 3.5.1)
#>
#> [1] /home/arch/R/x86_64-pc-linux-gnu-library/3.6
#> [2] /usr/lib/R/library
When I encountered this same error it was because I had the .Rmd file for the presentation open in a separate window. Once I returned it to the main window, xaringan::inf_mr() displayed the presentation in the Viewer tab with no problem.

R tmap:: make title part of the legend

In the example below: how do I make the title "Main title" part of the legend? The titles for col and size should remain the same and be used as subtitles.
As far as I understand the documentation it should work setting title.snap.to.legend = TRUE but it does not work. Minimum example:
library(tmap)
data(World, metro)
tm_shape(World) + tm_fill()+
tm_shape(metro) +
tm_symbols(
size = "pop2020",
col = "pop2020",
title.size = "title 1",
title.col = "title 2",
legend.size.is.portrait=TRUE) +
tm_layout(legend.bg.color = "gray",
legend.frame = "black",
title="Main title",
title.snap.to.legend = TRUE)
That gives:
I want the main title to be placed on top of the legend elements within the legend frame.
Not sure why this is not working, but below is a sloppy, fast hack with adding several new lines \n in front of the title until you push it close to the top of the legend. Others might give better answers. This might be an issue, so consider opening one here.
library(tmap)
#> Warning: package 'tmap' was built under R version 3.5.2
data(World, metro)
tm_shape(World) + tm_fill()+
tm_shape(metro) +
tm_symbols(
size = "pop2020",
col = "pop2020",
title.size = "title 1",
title.col = "title 2",
legend.size.is.portrait=TRUE) +
tm_layout(legend.bg.color = "gray",
legend.frame = "black",
title="\n\n\n Main title") # add \n to push the title down
Created on 2019-02-06 by the reprex package (v0.2.1)
devtools::session_info()
#> - Session info ----------------------------------------------------------
#> setting value
#> version R version 3.5.1 (2018-07-02)
#> os Windows 7 x64 SP 1
#> system x86_64, mingw32
#> ui RTerm
#> language (EN)
#> collate English_United States.1252
#> ctype English_United States.1252
#> date 2019-02-06
#>
#> - Packages --------------------------------------------------------------
#> package * version date lib source
#> assertthat 0.2.0 2017-04-11 [1] CRAN (R 3.5.1)
#> backports 1.1.2 2017-12-13 [1] CRAN (R 3.5.0)
#> base64enc 0.1-3 2015-07-28 [1] CRAN (R 3.5.0)
#> callr 3.0.0 2018-08-24 [1] CRAN (R 3.5.1)
#> class 7.3-14 2015-08-30 [2] CRAN (R 3.5.1)
#> classInt 0.2-3 2018-04-16 [1] CRAN (R 3.5.1)
#> cli 1.0.1 2018-09-25 [1] CRAN (R 3.5.1)
#> codetools 0.2-15 2016-10-05 [2] CRAN (R 3.5.1)
#> colorspace 1.3-2 2016-12-14 [1] CRAN (R 3.5.1)
#> crayon 1.3.4 2017-09-16 [1] CRAN (R 3.5.1)
#> crosstalk 1.0.0 2016-12-21 [1] CRAN (R 3.5.1)
#> curl 3.2 2018-03-28 [1] CRAN (R 3.5.1)
#> DBI 1.0.0 2018-05-02 [1] CRAN (R 3.5.1)
#> desc 1.2.0 2018-05-01 [1] CRAN (R 3.5.1)
#> devtools 2.0.1 2018-10-26 [1] CRAN (R 3.5.1)
#> dichromat 2.0-0 2013-01-24 [1] CRAN (R 3.5.0)
#> digest 0.6.18 2018-10-10 [1] CRAN (R 3.5.1)
#> e1071 1.7-0 2018-07-28 [1] CRAN (R 3.5.1)
#> evaluate 0.12 2018-10-09 [1] CRAN (R 3.5.1)
#> fs 1.2.6 2018-08-23 [1] CRAN (R 3.5.1)
#> glue 1.3.0 2018-07-17 [1] CRAN (R 3.5.1)
#> htmltools 0.3.6 2017-04-28 [1] CRAN (R 3.5.1)
#> htmlwidgets 1.3 2018-09-30 [1] CRAN (R 3.5.1)
#> httpuv 1.4.5 2018-07-19 [1] CRAN (R 3.5.1)
#> httr 1.3.1 2017-08-20 [1] CRAN (R 3.5.1)
#> KernSmooth 2.23-15 2015-06-29 [2] CRAN (R 3.5.1)
#> knitr 1.20 2018-02-20 [1] CRAN (R 3.5.1)
#> later 0.7.5 2018-09-18 [1] CRAN (R 3.5.1)
#> lattice 0.20-35 2017-03-25 [2] CRAN (R 3.5.1)
#> leaflet 2.0.2 2018-08-27 [1] CRAN (R 3.5.1)
#> lwgeom 0.1-5 2018-12-07 [1] CRAN (R 3.5.1)
#> magrittr 1.5 2014-11-22 [1] CRAN (R 3.5.1)
#> mapview 2.6.0 2018-09-16 [1] CRAN (R 3.5.1)
#> memoise 1.1.0 2017-04-21 [1] CRAN (R 3.5.1)
#> mime 0.6 2018-10-05 [1] CRAN (R 3.5.1)
#> munsell 0.5.0 2018-06-12 [1] CRAN (R 3.5.1)
#> pkgbuild 1.0.2 2018-10-16 [1] CRAN (R 3.5.1)
#> pkgload 1.0.2 2018-10-29 [1] CRAN (R 3.5.1)
#> png 0.1-7 2013-12-03 [1] CRAN (R 3.5.0)
#> prettyunits 1.0.2 2015-07-13 [1] CRAN (R 3.5.1)
#> processx 3.2.0 2018-08-16 [1] CRAN (R 3.5.1)
#> promises 1.0.1 2018-04-13 [1] CRAN (R 3.5.1)
#> ps 1.2.1 2018-11-06 [1] CRAN (R 3.5.1)
#> R6 2.3.0 2018-10-04 [1] CRAN (R 3.5.1)
#> raster 2.8-4 2018-11-03 [1] CRAN (R 3.5.1)
#> RColorBrewer 1.1-2 2014-12-07 [1] CRAN (R 3.5.0)
#> Rcpp 1.0.0 2018-11-07 [1] CRAN (R 3.5.1)
#> remotes 2.0.2 2018-10-30 [1] CRAN (R 3.5.1)
#> rgdal 1.3-6 2018-10-16 [1] CRAN (R 3.5.1)
#> rgeos 0.4-2 2018-11-08 [1] CRAN (R 3.5.1)
#> rlang 0.3.0.1 2018-10-25 [1] CRAN (R 3.5.1)
#> rmarkdown 1.10 2018-06-11 [1] CRAN (R 3.5.1)
#> rprojroot 1.3-2 2018-01-03 [1] CRAN (R 3.5.1)
#> satellite 1.0.1 2017-10-18 [1] CRAN (R 3.5.1)
#> scales 1.0.0 2018-08-09 [1] CRAN (R 3.5.1)
#> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.5.1)
#> sf 0.7-1 2018-10-24 [1] CRAN (R 3.5.1)
#> shiny 1.2.0 2018-11-02 [1] CRAN (R 3.5.1)
#> sp 1.3-1 2018-06-05 [1] CRAN (R 3.5.1)
#> spData 0.2.9.4 2018-09-15 [1] CRAN (R 3.5.1)
#> stringi 1.2.4 2018-07-20 [1] CRAN (R 3.5.1)
#> stringr 1.3.1 2018-05-10 [1] CRAN (R 3.5.1)
#> tmap * 2.2 2019-01-05 [1] CRAN (R 3.5.2)
#> tmaptools 2.0-1 2018-08-07 [1] CRAN (R 3.5.1)
#> units 0.6-1 2018-09-21 [1] CRAN (R 3.5.1)
#> usethis 1.4.0 2018-08-14 [1] CRAN (R 3.5.1)
#> viridisLite 0.3.0 2018-02-01 [1] CRAN (R 3.5.1)
#> webshot 0.5.1 2018-09-28 [1] CRAN (R 3.5.1)
#> withr 2.1.2 2018-03-15 [1] CRAN (R 3.5.1)
#> XML 3.98-1.16 2018-08-19 [1] CRAN (R 3.5.1)
#> xml2 1.2.0 2018-01-24 [1] CRAN (R 3.5.1)
#> xtable 1.8-3 2018-08-29 [1] CRAN (R 3.5.1)
#> yaml 2.2.0 2018-07-25 [1] CRAN (R 3.5.1)

Resources