www.r-bloggers.com
Open in
urlscan Pro
188.114.97.12
Public Scan
URL:
https://www.r-bloggers.com/2022/03/self-documenting-plots-in-ggplot2/
Submission Tags: falconsandbox
Submission: On February 17 via api from US — Scanned from NL
Submission Tags: falconsandbox
Submission: On February 17 via api from US — Scanned from NL
Form analysis
3 forms found in the DOMhttps://www.google.com/cse
<form id="searchform" action="https://www.google.com/cse" target="_blank">
<div>
<input type="hidden" name="cx" value="005359090438081006639:paz69t-s8ua">
<input type="hidden" name="ie" value="UTF-8">
<input type="text" value="" name="q" id="q" autocomplete="on" style="font-size:16px;" placeholder="Search R-bloggers..">
<input type="submit" id="searchsubmit2" name="sa" value="Go" style="font-size:16px;">
</div>
<input type="hidden" name="bIDiEKaSr" value="[NwX]avgpyM"><input type="hidden" name="JtlBfjh" value="JlitU.M3"><input type="hidden" name="BNXYvMTtg" value="m6Py@WO3Y0u">
</form>
POST https://r-bloggers.com/phplist/?p=subscribe&id=1
<form style="width:202px; float:left;" action="https://r-bloggers.com/phplist/?p=subscribe&id=1" method="post" target="popupwindow">
<input type="text" style="width:110px" onclick="if (!window.__cfRLUnblockHandlers) return false; if (this.value == 'Your e-mail here') this.value = '';" value="Your e-mail here" name="email">
<input type="hidden" value="RBloggers" name="uri"><input type="hidden" name="loc" value="en_US"><input type="submit" value="Subscribe">
<input type="hidden" name="bIDiEKaSr" value="[NwX]avgpyM"><input type="hidden" name="JtlBfjh" value="JlitU.M3"><input type="hidden" name="BNXYvMTtg" value="m6Py@WO3Y0u">
</form>
POST https://r-bloggers.com/phplist/?p=subscribe&id=1&email=
<form action="https://r-bloggers.com/phplist/?p=subscribe&id=1&email=" method="post" class="snp-subscribeform snp_subscribeform" target="_blank">
<fieldset>
<div class="snp-field">
<input type="text" name="email" id="snp_email" placeholder="Your E-mail..." class="snp-field snp-field-email">
</div>
<button type="submit" class="snp-submit">Submit</button>
</fieldset>
<input type="hidden" name="bIDiEKaSr" value="[NwX]avgpyM"><input type="hidden" name="JtlBfjh" value="JlitU.M3"><input type="hidden" name="BNXYvMTtg" value="m6Py@WO3Y0u">
</form>
Text Content
MENU * Home * About * RSS * add your blog! * Learn R * R jobs ► * Submit a new job (it’s free) * Browse latest jobs (also free) * Contact us R-BLOGGERS R NEWS AND TUTORIALS CONTRIBUTED BY HUNDREDS OF R BLOGGERS * Home * About * RSS * add your blog! * Learn R * R jobs * Submit a new job (it’s free) * Browse latest jobs (also free) * Contact us SELF-DOCUMENTING PLOTS IN GGPLOT2 Posted on March 10, 2022 by Higher Order Functions in R bloggers | 0 Comments [This article was first published on Higher Order Functions, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here) -------------------------------------------------------------------------------- Want to share your content on R-bloggers? click here if you have a blog, or here if you don't. ShareTweet When I am showing off a plotting technique in ggplot2, I sometimes like to include the R code that produced the plot as part of the plot. Here is an example I made to demonstrate the debug debug parameter in element_text() element_text(): library(ggplot2) self_document( ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = "white") + labs(title = "A basic histogram") + theme(axis.title = element_text(debug = TRUE)) ) library(ggplot2) self_document( ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = "white") + labs(title = "A basic histogram") + theme(axis.title = element_text(debug = TRUE)) ) library(ggplot2) self_document( ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = "white") + labs(title = "A basic histogram") + theme(axis.title = element_text(debug = TRUE)) ) Let’s call these “self-documenting plots”. If we’re feeling nerdy, we might also call them “qquines”, although they are not true quines. In this post, we will build up a self_document() self_document() function from scratch. Here are the problems we need to sort out: * how to put plotting code above a title * how to capture plotting code and convert it into text CREATING THE CODE ANNOTATION As a first step, let’s just treat our plotting code as a string that is ready to use for annotation. p_text <- 'ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = "white") + labs(title = "A basic histogram")' p_plot <- ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = "white") + labs(title = "A basic histogram") p_text <- 'ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = "white") + labs(title = "A basic histogram")' p_plot <- ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = "white") + labs(title = "A basic histogram") p_text <- 'ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = "white") + labs(title = "A basic histogram")' p_plot <- ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = "white") + labs(title = "A basic histogram") In order to have a titled plot along with this annotation, we need some way to combine these two graphical objects together (the code and the plot produced by ggplot2). I like the patchwork package for this job. Here we use wrap_elements() wrap_elements() to capture the plot into a “patch” that patchwork can annotate. library(patchwork) wrap_elements(p_plot) + plot_annotation(title = p_text) library(patchwork) wrap_elements(p_plot) + plot_annotation(title = p_text) library(patchwork) wrap_elements(p_plot) + plot_annotation(title = p_text) Let’s style this title to use a monospaced font. I use Windows and like Consolas, so I will use that font. # Use default mono font if "Consolas" is not available extrafont::loadfonts(device = "win", quiet = TRUE) monofont <- ifelse( extrafont::choose_font("Consolas") == "", "mono", "Consolas" ) title_theme <- theme( plot.title = element_text( family = monofont, hjust = 0, size = rel(.9), margin = margin(0, 0, 5.5, 0, unit = "pt") ) ) wrap_elements(p_plot) + plot_annotation(title = p_text, theme = title_theme) # Use default mono font if "Consolas" is not available extrafont::loadfonts(device = "win", quiet = TRUE) monofont <- ifelse( extrafont::choose_font("Consolas") == "", "mono", "Consolas" ) title_theme <- theme( plot.title = element_text( family = monofont, hjust = 0, size = rel(.9), margin = margin(0, 0, 5.5, 0, unit = "pt") ) ) wrap_elements(p_plot) + plot_annotation(title = p_text, theme = title_theme) # Use default mono font if "Consolas" is not available extrafont::loadfonts(device = "win", quiet = TRUE) monofont <- ifelse( extrafont::choose_font("Consolas") == "", "mono", "Consolas" ) title_theme <- theme( plot.title = element_text( family = monofont, hjust = 0, size = rel(.9), margin = margin(0, 0, 5.5, 0, unit = "pt") ) ) wrap_elements(p_plot) + plot_annotation(title = p_text, theme = title_theme) One problem with this setup is that the plotting code has to be edited in two places: the plot p_plot p_plot and the title p_text p_text. As a result, it’s easy for these two pieces of code to fall out of sync with each other, turning our self-documenting plot into a lying liar plot. The solution is pretty easy: Tell R that p_text p_text is code with parse() parse() and evaluate the code with eval() eval(): wrap_elements(eval(parse(text = p_text))) + plot_annotation(title = p_text, theme = title_theme) wrap_elements(eval(parse(text = p_text))) + plot_annotation(title = p_text, theme = title_theme) wrap_elements(eval(parse(text = p_text))) + plot_annotation(title = p_text, theme = title_theme) This works. It gets the job done. But we find ourselves in a clumsy workflow, either having to edit R code inside of quotes or editing the plot interactively and then having to wrap it in quotes. Let’s do better. CAPTURING PLOTTING CODE AS A STRING Time for some nonstandard evaluation. I will use the rlang package, although in principle we could use functions in base R to accomplish these goals. First, we are going to use rlang::expr() rlang::expr() to capture/quote/defuse the R code as an expression. We can print the code as code, print it as text, and use eval() eval() to show the plot. p_code <- rlang::expr( ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = "white") + labs(title = "A basic histogram") ) # print the expressions p_code #> ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = "white") + #> labs(title = "A basic histogram") # expression => text rlang::expr_text(p_code) #> [1] "ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = \"white\") + \n labs(title = \"A basic histogram\")" eval(p_code) p_code <- rlang::expr( ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = "white") + labs(title = "A basic histogram") ) # print the expressions p_code #> ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = "white") + #> labs(title = "A basic histogram") # expression => text rlang::expr_text(p_code) #> [1] "ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = \"white\") + \n labs(title = \"A basic histogram\")" eval(p_code) p_code <- rlang::expr( ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = "white") + labs(title = "A basic histogram") ) # print the expressions p_code #> ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = "white") + #> labs(title = "A basic histogram") # expression => text rlang::expr_text(p_code) #> [1] "ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = \"white\") + \n labs(title = \"A basic histogram\")" eval(p_code) Then, it should be straightforward to make the self-documenting plot, right? p_code <- rlang::expr( ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = "white") + labs(title = "A basic histogram") ) wrap_elements(eval(p_code)) + plot_annotation(title = rlang::expr_text(p_code), theme = title_theme) p_code <- rlang::expr( ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = "white") + labs(title = "A basic histogram") ) wrap_elements(eval(p_code)) + plot_annotation(title = rlang::expr_text(p_code), theme = title_theme) p_code <- rlang::expr( ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = "white") + labs(title = "A basic histogram") ) wrap_elements(eval(p_code)) + plot_annotation(title = rlang::expr_text(p_code), theme = title_theme) Hey, it reformatted the title! Indeed, in the process of capturing the code, the code formatting was lost. To get something closer to the source code we provided, we have to reformat the captured code before we print it. The styler package provides a suite of functions for reformatting code. We can define our own coding styles/formatting rules to customize how styler works. I like the styler rules used by Garrick Aden-Buie in his grkstyle package, so I will use grkstyle::grk_style_text() grkstyle::grk_style_text() to reformat the code. p_code <- rlang::expr( ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = "white") + labs(title = "A basic histogram") ) wrap_elements(eval(p_code)) + plot_annotation( title = rlang::expr_text(p_code) |> grkstyle::grk_style_text() |> # reformatting returns a vector of lines, # so we have to combine them paste0(collapse = "\n"), theme = title_theme ) p_code <- rlang::expr( ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = "white") + labs(title = "A basic histogram") ) wrap_elements(eval(p_code)) + plot_annotation( title = rlang::expr_text(p_code) |> grkstyle::grk_style_text() |> # reformatting returns a vector of lines, # so we have to combine them paste0(collapse = "\n"), theme = title_theme ) p_code <- rlang::expr( ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = "white") + labs(title = "A basic histogram") ) wrap_elements(eval(p_code)) + plot_annotation( title = rlang::expr_text(p_code) |> grkstyle::grk_style_text() |> # reformatting returns a vector of lines, # so we have to combine them paste0(collapse = "\n"), theme = title_theme ) PUTTING IT ALL TOGETHER When we write our self_document() self_document() function, the only change we have to make is using rlang::enexpr() rlang::enexpr() instead rlang::expr() rlang::expr(). The en-variant is used when we want to en-quote exactly what the user provided. Aside from that change, our self_document() self_document() function just bundles together all of the code we developed above: self_document <- function(expr) { monofont <- ifelse( extrafont::choose_font("Consolas") == "", "mono", "Consolas" ) p <- rlang::enexpr(expr) title <- rlang::expr_text(p) |> grkstyle::grk_style_text() |> paste0(collapse = "\n") patchwork::wrap_elements(eval(p)) + patchwork::plot_annotation( title = title, theme = theme( plot.title = element_text( family = monofont, hjust = 0, size = rel(.9), margin = margin(0, 0, 5.5, 0, unit = "pt") ) ) ) } self_document <- function(expr) { monofont <- ifelse( extrafont::choose_font("Consolas") == "", "mono", "Consolas" ) p <- rlang::enexpr(expr) title <- rlang::expr_text(p) |> grkstyle::grk_style_text() |> paste0(collapse = "\n") patchwork::wrap_elements(eval(p)) + patchwork::plot_annotation( title = title, theme = theme( plot.title = element_text( family = monofont, hjust = 0, size = rel(.9), margin = margin(0, 0, 5.5, 0, unit = "pt") ) ) ) } self_document <- function(expr) { monofont <- ifelse( extrafont::choose_font("Consolas") == "", "mono", "Consolas" ) p <- rlang::enexpr(expr) title <- rlang::expr_text(p) |> grkstyle::grk_style_text() |> paste0(collapse = "\n") patchwork::wrap_elements(eval(p)) + patchwork::plot_annotation( title = title, theme = theme( plot.title = element_text( family = monofont, hjust = 0, size = rel(.9), margin = margin(0, 0, 5.5, 0, unit = "pt") ) ) ) } And let’s confirm that it works. library(ggplot2) self_document( ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = "white") + labs(title = "A basic histogram") ) library(ggplot2) self_document( ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = "white") + labs(title = "A basic histogram") ) library(ggplot2) self_document( ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = "white") + labs(title = "A basic histogram") ) Because we developed this function on top of rlang, we can do some tricks like injecting a variable’s value when capturing the code. For example, here I use !! color !! color to replace the color color variable with the actual value. color <- "white" self_document( ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = !! color) + labs(title = "A basic histogram") ) color <- "white" self_document( ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = !! color) + labs(title = "A basic histogram") ) color <- "white" self_document( ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = !! color) + labs(title = "A basic histogram") ) And if you are wondering, yes, we can self_document() self_document() a self_document() self_document() plot. self_document( self_document( ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = "white") + labs(title = "A basic histogram") ) ) self_document( self_document( ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = "white") + labs(title = "A basic histogram") ) ) self_document( self_document( ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = "white") + labs(title = "A basic histogram") ) ) ALAS, COMMENTS ARE LOST One downside of this approach is that helpful comments are lost. self_document( ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = !! color) + # get rid of that grey theme_minimal() + labs(title = "A basic histogram") ) self_document( ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = !! color) + # get rid of that grey theme_minimal() + labs(title = "A basic histogram") ) self_document( ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = !! color) + # get rid of that grey theme_minimal() + labs(title = "A basic histogram") ) I am not sure how to include comments. One place where comments are stored and printed is in function bodies: f <- function() { ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = !! color) + # get rid of that grey theme_minimal() + labs(title = "A basic histogram") } print(f, useSource = TRUE) #> function() { #> ggplot(mtcars, aes(x = mpg)) + #> geom_histogram(bins = 20, color = !! color) + #> # get rid of that grey #> theme_minimal() + #> labs(title = "A basic histogram") #> } #> <environment: 0x000001746d339b68> f <- function() { ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = !! color) + # get rid of that grey theme_minimal() + labs(title = "A basic histogram") } print(f, useSource = TRUE) #> function() { #> ggplot(mtcars, aes(x = mpg)) + #> geom_histogram(bins = 20, color = !! color) + #> # get rid of that grey #> theme_minimal() + #> labs(title = "A basic histogram") #> } #> <environment: 0x000001746d339b68> f <- function() { ggplot(mtcars, aes(x = mpg)) + geom_histogram(bins = 20, color = !! color) + # get rid of that grey theme_minimal() + labs(title = "A basic histogram") } print(f, useSource = TRUE) #> function() { #> ggplot(mtcars, aes(x = mpg)) + #> geom_histogram(bins = 20, color = !! color) + #> # get rid of that grey #> theme_minimal() + #> labs(title = "A basic histogram") #> } #> <environment: 0x000001746d339b68> I have no idea how to go about exploiting this feature for self-documenting plots, however. -------------------------------------------------------------------------------- Last knitted on 2022-03-10. Source code on GitHub.1 1. sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R Under development (unstable) (2022-03-02 r81842 ucrt) #> os Windows 10 x64 (build 22000) #> system x86_64, mingw32 #> ui RTerm #> language (EN) #> collate English_United States.utf8 #> ctype English_United States.utf8 #> tz America/Chicago #> date 2022-03-10 #> pandoc NA #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.2.0) #> backports 1.4.1 2021-12-13 [1] CRAN (R 4.2.0) #> cachem 1.0.6 2021-08-19 [1] CRAN (R 4.2.0) #> cli 3.2.0 2022-02-14 [1] CRAN (R 4.2.0) #> colorspace 2.0-3 2022-02-21 [1] CRAN (R 4.2.0) #> crayon 1.5.0 2022-02-14 [1] CRAN (R 4.2.0) #> DBI 1.1.2 2021-12-20 [1] CRAN (R 4.2.0) #> digest 0.6.29 2021-12-01 [1] CRAN (R 4.2.0) #> downlit 0.4.0 2021-10-29 [1] CRAN (R 4.2.0) #> dplyr 1.0.8 2022-02-08 [1] CRAN (R 4.2.0) #> ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.2.0) #> evaluate 0.15 2022-02-18 [1] CRAN (R 4.2.0) #> extrafont 0.17 2014-12-08 [1] CRAN (R 4.2.0) #> extrafontdb 1.0 2012-06-11 [1] CRAN (R 4.2.0) #> fansi 1.0.2 2022-01-14 [1] CRAN (R 4.2.0) #> farver 2.1.0 2021-02-28 [1] CRAN (R 4.2.0) #> fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.2.0) #> generics 0.1.2 2022-01-31 [1] CRAN (R 4.2.0) #> ggplot2 * 3.3.5 2021-06-25 [1] CRAN (R 4.2.0) #> git2r 0.29.0 2021-11-22 [1] CRAN (R 4.2.0) #> glue 1.6.2 2022-02-24 [1] CRAN (R 4.2.0) #> grkstyle 0.0.3 2022-03-10 [1] Github (gadenbuie/grkstyle@6a7011c) #> gtable 0.3.0 2019-03-25 [1] CRAN (R 4.2.0) #> here 1.0.1 2020-12-13 [1] CRAN (R 4.2.0) #> highr 0.9 2021-04-16 [1] CRAN (R 4.2.0) #> knitr * 1.37 2021-12-16 [1] CRAN (R 4.2.0) #> labeling 0.4.2 2020-10-20 [1] CRAN (R 4.2.0) #> lifecycle 1.0.1 2021-09-24 [1] CRAN (R 4.2.0) #> magrittr 2.0.2 2022-01-26 [1] CRAN (R 4.2.0) #> memoise 2.0.1 2021-11-26 [1] CRAN (R 4.2.0) #> munsell 0.5.0 2018-06-12 [1] CRAN (R 4.2.0) #> patchwork * 1.1.1 2020-12-17 [1] CRAN (R 4.2.0) #> pillar 1.7.0 2022-02-01 [1] CRAN (R 4.2.0) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.2.0) #> purrr 0.3.4 2020-04-17 [1] CRAN (R 4.2.0) #> R.cache 0.15.0 2021-04-30 [1] CRAN (R 4.2.0) #> R.methodsS3 1.8.1 2020-08-26 [1] CRAN (R 4.2.0) #> R.oo 1.24.0 2020-08-26 [1] CRAN (R 4.2.0) #> R.utils 2.11.0 2021-09-26 [1] CRAN (R 4.2.0) #> R6 2.5.1 2021-08-19 [1] CRAN (R 4.2.0) #> ragg 1.2.2 2022-02-21 [1] CRAN (R 4.2.0) #> rlang 1.0.2 2022-03-04 [1] CRAN (R 4.2.0) #> rprojroot 2.0.2 2020-11-15 [1] CRAN (R 4.2.0) #> rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.2.0) #> Rttf2pt1 1.3.8 2020-01-10 [1] CRAN (R 4.2.0) #> scales 1.1.1 2020-05-11 [1] CRAN (R 4.2.0) #> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.2.0) #> stringi 1.7.6 2021-11-29 [1] CRAN (R 4.2.0) #> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.2.0) #> styler 1.6.2 2021-09-23 [1] CRAN (R 4.2.0) #> systemfonts 1.0.4 2022-02-11 [1] CRAN (R 4.2.0) #> textshaping 0.3.6 2021-10-13 [1] CRAN (R 4.2.0) #> tibble 3.1.6 2021-11-07 [1] CRAN (R 4.2.0) #> tidyselect 1.1.2 2022-02-21 [1] CRAN (R 4.2.0) #> utf8 1.2.2 2021-07-24 [1] CRAN (R 4.2.0) #> vctrs 0.3.8 2021-04-29 [1] CRAN (R 4.2.0) #> withr 2.5.0 2022-03-03 [1] CRAN (R 4.2.0) #> xfun 0.30 2022-03-02 [1] CRAN (R 4.2.0) #> yaml 2.3.5 2022-02-21 [1] CRAN (R 4.2.0) #> #> [1] C:/Users/trist/AppData/Local/R/win-library/4.2 #> [2] C:/Program Files/R/R-devel/library #> #> ────────────────────────────────────────────────────────────────────────────── sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R Under development (unstable) (2022-03-02 r81842 ucrt) #> os Windows 10 x64 (build 22000) #> system x86_64, mingw32 #> ui RTerm #> language (EN) #> collate English_United States.utf8 #> ctype English_United States.utf8 #> tz America/Chicago #> date 2022-03-10 #> pandoc NA #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.2.0) #> backports 1.4.1 2021-12-13 [1] CRAN (R 4.2.0) #> cachem 1.0.6 2021-08-19 [1] CRAN (R 4.2.0) #> cli 3.2.0 2022-02-14 [1] CRAN (R 4.2.0) #> colorspace 2.0-3 2022-02-21 [1] CRAN (R 4.2.0) #> crayon 1.5.0 2022-02-14 [1] CRAN (R 4.2.0) #> DBI 1.1.2 2021-12-20 [1] CRAN (R 4.2.0) #> digest 0.6.29 2021-12-01 [1] CRAN (R 4.2.0) #> downlit 0.4.0 2021-10-29 [1] CRAN (R 4.2.0) #> dplyr 1.0.8 2022-02-08 [1] CRAN (R 4.2.0) #> ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.2.0) #> evaluate 0.15 2022-02-18 [1] CRAN (R 4.2.0) #> extrafont 0.17 2014-12-08 [1] CRAN (R 4.2.0) #> extrafontdb 1.0 2012-06-11 [1] CRAN (R 4.2.0) #> fansi 1.0.2 2022-01-14 [1] CRAN (R 4.2.0) #> farver 2.1.0 2021-02-28 [1] CRAN (R 4.2.0) #> fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.2.0) #> generics 0.1.2 2022-01-31 [1] CRAN (R 4.2.0) #> ggplot2 * 3.3.5 2021-06-25 [1] CRAN (R 4.2.0) #> git2r 0.29.0 2021-11-22 [1] CRAN (R 4.2.0) #> glue 1.6.2 2022-02-24 [1] CRAN (R 4.2.0) #> grkstyle 0.0.3 2022-03-10 [1] Github (gadenbuie/grkstyle@6a7011c) #> gtable 0.3.0 2019-03-25 [1] CRAN (R 4.2.0) #> here 1.0.1 2020-12-13 [1] CRAN (R 4.2.0) #> highr 0.9 2021-04-16 [1] CRAN (R 4.2.0) #> knitr * 1.37 2021-12-16 [1] CRAN (R 4.2.0) #> labeling 0.4.2 2020-10-20 [1] CRAN (R 4.2.0) #> lifecycle 1.0.1 2021-09-24 [1] CRAN (R 4.2.0) #> magrittr 2.0.2 2022-01-26 [1] CRAN (R 4.2.0) #> memoise 2.0.1 2021-11-26 [1] CRAN (R 4.2.0) #> munsell 0.5.0 2018-06-12 [1] CRAN (R 4.2.0) #> patchwork * 1.1.1 2020-12-17 [1] CRAN (R 4.2.0) #> pillar 1.7.0 2022-02-01 [1] CRAN (R 4.2.0) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.2.0) #> purrr 0.3.4 2020-04-17 [1] CRAN (R 4.2.0) #> R.cache 0.15.0 2021-04-30 [1] CRAN (R 4.2.0) #> R.methodsS3 1.8.1 2020-08-26 [1] CRAN (R 4.2.0) #> R.oo 1.24.0 2020-08-26 [1] CRAN (R 4.2.0) #> R.utils 2.11.0 2021-09-26 [1] CRAN (R 4.2.0) #> R6 2.5.1 2021-08-19 [1] CRAN (R 4.2.0) #> ragg 1.2.2 2022-02-21 [1] CRAN (R 4.2.0) #> rlang 1.0.2 2022-03-04 [1] CRAN (R 4.2.0) #> rprojroot 2.0.2 2020-11-15 [1] CRAN (R 4.2.0) #> rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.2.0) #> Rttf2pt1 1.3.8 2020-01-10 [1] CRAN (R 4.2.0) #> scales 1.1.1 2020-05-11 [1] CRAN (R 4.2.0) #> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.2.0) #> stringi 1.7.6 2021-11-29 [1] CRAN (R 4.2.0) #> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.2.0) #> styler 1.6.2 2021-09-23 [1] CRAN (R 4.2.0) #> systemfonts 1.0.4 2022-02-11 [1] CRAN (R 4.2.0) #> textshaping 0.3.6 2021-10-13 [1] CRAN (R 4.2.0) #> tibble 3.1.6 2021-11-07 [1] CRAN (R 4.2.0) #> tidyselect 1.1.2 2022-02-21 [1] CRAN (R 4.2.0) #> utf8 1.2.2 2021-07-24 [1] CRAN (R 4.2.0) #> vctrs 0.3.8 2021-04-29 [1] CRAN (R 4.2.0) #> withr 2.5.0 2022-03-03 [1] CRAN (R 4.2.0) #> xfun 0.30 2022-03-02 [1] CRAN (R 4.2.0) #> yaml 2.3.5 2022-02-21 [1] CRAN (R 4.2.0) #> #> [1] C:/Users/trist/AppData/Local/R/win-library/4.2 #> [2] C:/Program Files/R/R-devel/library #> #> ────────────────────────────────────────────────────────────────────────────── sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R Under development (unstable) (2022-03-02 r81842 ucrt) #> os Windows 10 x64 (build 22000) #> system x86_64, mingw32 #> ui RTerm #> language (EN) #> collate English_United States.utf8 #> ctype English_United States.utf8 #> tz America/Chicago #> date 2022-03-10 #> pandoc NA #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.2.0) #> backports 1.4.1 2021-12-13 [1] CRAN (R 4.2.0) #> cachem 1.0.6 2021-08-19 [1] CRAN (R 4.2.0) #> cli 3.2.0 2022-02-14 [1] CRAN (R 4.2.0) #> colorspace 2.0-3 2022-02-21 [1] CRAN (R 4.2.0) #> crayon 1.5.0 2022-02-14 [1] CRAN (R 4.2.0) #> DBI 1.1.2 2021-12-20 [1] CRAN (R 4.2.0) #> digest 0.6.29 2021-12-01 [1] CRAN (R 4.2.0) #> downlit 0.4.0 2021-10-29 [1] CRAN (R 4.2.0) #> dplyr 1.0.8 2022-02-08 [1] CRAN (R 4.2.0) #> ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.2.0) #> evaluate 0.15 2022-02-18 [1] CRAN (R 4.2.0) #> extrafont 0.17 2014-12-08 [1] CRAN (R 4.2.0) #> extrafontdb 1.0 2012-06-11 [1] CRAN (R 4.2.0) #> fansi 1.0.2 2022-01-14 [1] CRAN (R 4.2.0) #> farver 2.1.0 2021-02-28 [1] CRAN (R 4.2.0) #> fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.2.0) #> generics 0.1.2 2022-01-31 [1] CRAN (R 4.2.0) #> ggplot2 * 3.3.5 2021-06-25 [1] CRAN (R 4.2.0) #> git2r 0.29.0 2021-11-22 [1] CRAN (R 4.2.0) #> glue 1.6.2 2022-02-24 [1] CRAN (R 4.2.0) #> grkstyle 0.0.3 2022-03-10 [1] Github (gadenbuie/grkstyle@6a7011c) #> gtable 0.3.0 2019-03-25 [1] CRAN (R 4.2.0) #> here 1.0.1 2020-12-13 [1] CRAN (R 4.2.0) #> highr 0.9 2021-04-16 [1] CRAN (R 4.2.0) #> knitr * 1.37 2021-12-16 [1] CRAN (R 4.2.0) #> labeling 0.4.2 2020-10-20 [1] CRAN (R 4.2.0) #> lifecycle 1.0.1 2021-09-24 [1] CRAN (R 4.2.0) #> magrittr 2.0.2 2022-01-26 [1] CRAN (R 4.2.0) #> memoise 2.0.1 2021-11-26 [1] CRAN (R 4.2.0) #> munsell 0.5.0 2018-06-12 [1] CRAN (R 4.2.0) #> patchwork * 1.1.1 2020-12-17 [1] CRAN (R 4.2.0) #> pillar 1.7.0 2022-02-01 [1] CRAN (R 4.2.0) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.2.0) #> purrr 0.3.4 2020-04-17 [1] CRAN (R 4.2.0) #> R.cache 0.15.0 2021-04-30 [1] CRAN (R 4.2.0) #> R.methodsS3 1.8.1 2020-08-26 [1] CRAN (R 4.2.0) #> R.oo 1.24.0 2020-08-26 [1] CRAN (R 4.2.0) #> R.utils 2.11.0 2021-09-26 [1] CRAN (R 4.2.0) #> R6 2.5.1 2021-08-19 [1] CRAN (R 4.2.0) #> ragg 1.2.2 2022-02-21 [1] CRAN (R 4.2.0) #> rlang 1.0.2 2022-03-04 [1] CRAN (R 4.2.0) #> rprojroot 2.0.2 2020-11-15 [1] CRAN (R 4.2.0) #> rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.2.0) #> Rttf2pt1 1.3.8 2020-01-10 [1] CRAN (R 4.2.0) #> scales 1.1.1 2020-05-11 [1] CRAN (R 4.2.0) #> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.2.0) #> stringi 1.7.6 2021-11-29 [1] CRAN (R 4.2.0) #> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.2.0) #> styler 1.6.2 2021-09-23 [1] CRAN (R 4.2.0) #> systemfonts 1.0.4 2022-02-11 [1] CRAN (R 4.2.0) #> textshaping 0.3.6 2021-10-13 [1] CRAN (R 4.2.0) #> tibble 3.1.6 2021-11-07 [1] CRAN (R 4.2.0) #> tidyselect 1.1.2 2022-02-21 [1] CRAN (R 4.2.0) #> utf8 1.2.2 2021-07-24 [1] CRAN (R 4.2.0) #> vctrs 0.3.8 2021-04-29 [1] CRAN (R 4.2.0) #> withr 2.5.0 2022-03-03 [1] CRAN (R 4.2.0) #> xfun 0.30 2022-03-02 [1] CRAN (R 4.2.0) #> yaml 2.3.5 2022-02-21 [1] CRAN (R 4.2.0) #> #> [1] C:/Users/trist/AppData/Local/R/win-library/4.2 #> [2] C:/Program Files/R/R-devel/library #> #> ────────────────────────────────────────────────────────────────────────────── ↩ RELATED SIMPLIFYING GGPLOT2 CODE BY DOING NOTHING Recently, I joined the development team for bayesplot, an R package by the Stan team for plotting Bayesian models. Because visualizing Bayesian models in ggplot2 is a recurring topic here, it was a natural fit. So from time to time, I’ll post about some programming techniques and new features we… October 10, 2017 In "R bloggers" HIGHLIGHTING WITH GGPLOT2: THE OLD SCHOOL AND NEW SCHOOL WAY A tutorial showing how to highlight a subset of your data within the context of the full data set. We review the old school way (layering) and new school way (gghighlight). July 31, 2018 In "R bloggers" BEYOND BASIC R - PLOTTING WITH GGPLOT2 AND MULTIPLE PLOTS IN ONE FIGURE R can create almost any plot imaginable and as with most things in R if you don’t know where to start, try Google. The Introduction to R curriculum summarizes some of the most used plots, but cannot begin to expose people to the breadth of plot options that exist.There are… August 8, 2018 In "R bloggers" ShareTweet To leave a comment for the author, please follow the link and comment on their blog: Higher Order Functions. -------------------------------------------------------------------------------- R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job. -------------------------------------------------------------------------------- Want to share your content on R-bloggers? click here if you have a blog, or here if you don't. ← Previous post Next post → MOST VIEWED POSTS (WEEKLY) * PCA vs Autoencoders for Dimensionality Reduction * 5 Ways to Subset a Data Frame in R * How to write the first for loop in R * How to Calculate a Cumulative Average in R * Date Formats in R * Complete tutorial on using 'apply' functions in R * R – Sorting a data frame by the contents of a column SPONSORS -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --> -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- Our ads respect your privacy. Read our Privacy Policy page to learn more. -------------------------------------------------------------------------------- Contact us if you wish to help support R-bloggers, and place your banner here. RECENT POSTS * Something to note when using the merge function in R * Better Sentiment Analysis with sentiment.ai * Self-documenting plots in ggplot2 * Data Challenges for R Users * simplevis: new & improved! * Checking the inputs of your R functions * Imputing missing values in R * Creating a Dashboard Framework with AWS (Part 1) * BensstatsTalks#3: 5 Tips for Landing a Data Professional Role * Live COVID-19 Swiss vaccination analysis * Complete tutorial on using ‘apply’ functions in R * Getting to know Julia * Bootstraps & Bandings * How to Calculate a Cumulative Average in R * Some thoughts about the use of cloud services and web APIs in social science research JOBS FOR R-USERS * Junior Data Scientist / Quantitative economist * Senior Quantitative Analyst * R programmer * Data Scientist – CGIAR Excellence in Agronomy (Ref No: DDG-R4D/DS/1/CG/EA/06/20) * Data Analytics Auditor, Future of Audit Lead @ London or Newcastle PYTHON-BLOGGERS.COM (PYTHON/DATA-SCIENCE NEWS) * Dunn Index for K-Means Clustering Evaluation * Installing Python and Tensorflow with Jupyter Notebook Configurations * How to Get Twitter Data using Python * Visualizations with Altair * Spelling Corrector Program in Python * Spelling Checker Program in Python * Streamlit Tutorial: How to Deploy Streamlit Apps on RStudio Connect Full list of contributing R-bloggers ARCHIVES Archives Select Month March 2022 (34) February 2022 (152) January 2022 (154) December 2021 (172) November 2021 (145) October 2021 (199) September 2021 (202) August 2021 (153) July 2021 (171) June 2021 (195) May 2021 (196) April 2021 (183) March 2021 (221) February 2021 (225) January 2021 (252) December 2020 (295) November 2020 (266) October 2020 (276) September 2020 (249) August 2020 (226) July 2020 (268) June 2020 (231) May 2020 (332) April 2020 (326) March 2020 (279) February 2020 (259) January 2020 (250) December 2019 (241) November 2019 (214) October 2019 (230) September 2019 (227) August 2019 (270) July 2019 (258) June 2019 (242) May 2019 (272) April 2019 (289) March 2019 (302) February 2019 (259) January 2019 (282) December 2018 (257) November 2018 (285) October 2018 (298) September 2018 (285) August 2018 (266) July 2018 (327) June 2018 (296) May 2018 (315) April 2018 (296) March 2018 (287) February 2018 (239) January 2018 (328) December 2017 (260) November 2017 (265) October 2017 (287) September 2017 (287) August 2017 (328) July 2017 (279) June 2017 (312) May 2017 (341) April 2017 (319) March 2017 (364) February 2017 (312) January 2017 (364) December 2016 (345) November 2016 (288) October 2016 (298) September 2016 (249) August 2016 (280) July 2016 (322) June 2016 (259) May 2016 (288) April 2016 (258) March 2016 (295) February 2016 (261) January 2016 (334) December 2015 (300) November 2015 (234) October 2015 (255) September 2015 (232) August 2015 (261) July 2015 (240) June 2015 (205) May 2015 (228) April 2015 (203) March 2015 (256) February 2015 (207) January 2015 (237) December 2014 (230) November 2014 (219) October 2014 (212) September 2014 (253) August 2014 (214) July 2014 (226) June 2014 (234) May 2014 (238) April 2014 (256) March 2014 (286) February 2014 (266) January 2014 (260) December 2013 (261) November 2013 (237) October 2013 (233) September 2013 (214) August 2013 (223) July 2013 (254) June 2013 (271) May 2013 (260) April 2013 (278) March 2013 (277) February 2013 (293) January 2013 (340) December 2012 (306) November 2012 (274) October 2012 (304) September 2012 (268) August 2012 (262) July 2012 (247) June 2012 (297) May 2012 (283) April 2012 (295) March 2012 (304) February 2012 (264) January 2012 (278) December 2011 (251) November 2011 (261) October 2011 (280) September 2011 (187) August 2011 (258) July 2011 (219) June 2011 (224) May 2011 (239) April 2011 (267) March 2011 (249) February 2011 (203) January 2011 (209) December 2010 (188) November 2010 (172) October 2010 (219) September 2010 (185) August 2010 (203) July 2010 (175) June 2010 (167) May 2010 (164) April 2010 (152) March 2010 (165) February 2010 (135) January 2010 (121) December 2009 (126) November 2009 (66) October 2009 (87) September 2009 (65) August 2009 (56) July 2009 (64) June 2009 (54) May 2009 (35) April 2009 (38) March 2009 (40) February 2009 (33) January 2009 (42) December 2008 (16) November 2008 (14) October 2008 (10) September 2008 (8) August 2008 (11) July 2008 (7) June 2008 (8) May 2008 (8) April 2008 (4) March 2008 (5) February 2008 (6) January 2008 (10) December 2007 (3) November 2007 (5) October 2007 (9) September 2007 (7) August 2007 (21) July 2007 (9) June 2007 (3) May 2007 (3) April 2007 (1) March 2007 (5) February 2007 (4) November 2006 (1) October 2006 (2) August 2006 (3) July 2006 (1) June 2006 (1) May 2006 (3) April 2006 (1) March 2006 (1) February 2006 (5) January 2006 (1) October 2005 (1) September 2005 (3) May 2005 (1) OTHER SITES * SAS blogs * Jobs for R-users Copyright © 2022 | MH Corporate basic by MH Themes NEVER MISS AN UPDATE! SUBSCRIBE TO R-BLOGGERS TO RECEIVE E-MAILS WITH THE LATEST R POSTS. (YOU WILL NOT SEE THIS MESSAGE AGAIN.) Submit Click here to close (This popup will not appear again)