Table of Contents
About ggwebthemes
Not long ago, I published a post “Three ggplot2 Themes Optimized for the Web”, where I made some tweaks to my three favorite ggplot2
themes – theme_bw()
, theme_classic()
, and theme_void()
– to make them more readable and generally look better in graphics posted online, particularly in blog posts and similar publications.
I was happy to see that some people liked those and suggested that I should make a package. I tended to view packages as large collections of code and functions, but as Sébastien Rochette wisely put it, “If you have one function, create a package! If this simplifies your life, why not?” And since I will be frequently using these themes in subsequent posts, I’d like to make it as convenient as possible for the reader to install and use them.
So here is the ggwebthemes
package! It has the same three themes, which I have tweaked and improved some more.
The package is not yet on CRAN. You can install ggwebthemes
from GitLab:
# option 1: install using devtools
# install.packages("devtools")
devtools::install_gitlab("peterbar/ggwebthemes")
# option 2: install using remotes
# install.packages("remotes")
remotes::install_gitlab("peterbar/ggwebthemes")
# option 3: build from source
# use if you get error: package 'ggplot2' was built under R version...
install.packages("https://gitlab.com/peterbar/ggwebthemes/-/raw/master/tar/ggwebthemes_0.1.1.tar.gz",
repos = NULL, type = "source")
# load ggwebthemes
library(ggwebthemes)
Please report bugs and/or submit feature requests here. Since I am currently using WordPress (but thinking about switching to a static site), I am particularly interested in how these themes would behave on Hugo and in blogs created with R Markdown/blogdown, so if you have any feedback, it will be most appreciated.
You can find the package’s reference manual here.
Note: To avoid confusing the readers, I will be removing the original post “Three ggplot2 Themes Optimized for the Web”, which contains early versions of these themes. You can still find it on R-Bloggers in case you need it.
Examples
theme_web_bw
theme_web_classic
theme_web_void
Options 1 and 2 failed for me
Option 1 error messages
There are binary versions available but the source versions are
later:
binary source needs_compilation
rlang 0.4.9 0.4.10 TRUE
ggplot2 3.3.2 3.3.3 FALSE
Error: Failed to install ‘ggwebthemes’ from GitLab:
(converted from warning) cannot remove prior installation of package ‘vctrs’
Option 2 error messages
There are binary versions available but the source versions are
later:
binary source needs_compilation
rlang 0.4.9 0.4.10 TRUE
ggplot2 3.3.2 3.3.3 FALSE
Binaries will be installed
* installing *source* package ‘ggwebthemes’ …
** using staged installation
** R
** byte-compile and prepare package for lazy loading
Error: package or namespace load failed for ‘ggplot2’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):
there is no package called 'vctrs'
Error: package 'ggplot2' could not be loaded
Execution halted
ERROR: lazy loading failed for package 'ggwebthemes'
* removing 'C:/Users/KM TRADING/Documents/R/win-library/4.0/ggwebthemes'
Warning in install.packages :
installation of package ‘C:/Users/KMTRAD~1/AppData/Local/Temp/RtmpwzGfKH/downloaded_packages/ggwebthemes_0.1.1.tar.gz’ had non-zero exit status
Option 3 worked but I had to install vctrs manually then all was well
Hi Duncan,
Thank you for the feedback. Generally, please report bugs and/or submit feature requests here: https://gitlab.com/peterbar/ggwebthemes/-/issues
To address the issue you’ve reported, take a look at this and follow the debugging procedure: https://gitlab.com/peterbar/ggwebthemes/-/issues/1
Please let me know if this doesn’t help using the GitLab issues link.
Petr