An Example Usage of ggplot_add()

November 7, 2017

A generic function ggplot_add() was added to ggplot2 by this PR: Allow addition of custom objects by thomasp85 · Pull Request #2309 · tidyverse/ggplot2 I think creating a custom Geom or Stat and its constructor (geom_*() or stat_*()) is enough for the most of the extension packages of ggplot2, but some people, including me, need this. Why are there no geom_highlight()? Here is an example code of my package gghighlight: ... Read more

Publish R Markdown to Medium via An RStudio Addin

October 26, 2017

I created an experimental package to work with Medium API. mediumr: https://github.com/yutannihilation/mediumr/ mediumr allows you to knit and post R Markdown to Medium. Installation You can install mediumr from github with: devtools::install_github("yutannihilation/mediumr") Authentication Medium API requires a self-issued API token. (While they provide OAuth method, it’s hard for R users to use it since localhost is not allowed to specify in the callback URL.) Please issue a token in “Integration tokens” section of settings and set it as a environmental variable MEDIUM_API_TOKEN. ... Read more

How Not To Knit All Rmd Files With Blogdown

October 25, 2017

Blogdown is a cool package. But, if I complain about one thing, it will be the default behaviour of build_site(), which every blogdownners should execute everytime they wants to publish a new article. As stated in the documentation, build_site() will Compile all Rmd files and build the site through Hugo. (?build_site) Compiling all Rmd files is “safe” in the sense that we can notice if some Rmd becomes impossible to compile due to some breaking changes of some package. ... Read more

dplyr::select() Accepts Characters Since Version 0.7.0

October 25, 2017

Some of my friends didn’t aware that dplyr now accepts characters. Did you? For example, this expression select(iris, Sepal.Length, Petal.Length) can be also written in this way: select(iris, "Sepal.Length", "Petal.Length") or in this way: select(iris, c("Sepal.Length", "Petal.Length")) For the semantics of select(), you can find a good explanation in the vignette. Tidyeval? You may want to write some code that selects columns programmatically using variables. x <- c("col1", "col2") select(some_data, x) But, be fareful, x can be ambiguous. ... Read more

Confession: It's Me Who Committed the Change to Suppress .Rd Diffs On GitHub

October 21, 2017

You may notice that diffs of .Rd files are suppressed by default on GitHub since some time. Do you wonder who did this? It’s me, yay! This is my pull request: Ignore roxygen2 generated files by yutannihilation · Pull Request #3373 · github/linguist Though I thought I’ve done the right thing at that time, now I’m afraid this change may be bad for some cases… After the relese of roxygen2 6. ... Read more

Use CircleCI for R Projects

October 18, 2017

Why CircleCI? Yes, I know using Travis CI is this easy, thanks to devtools package: devtools::use_travis() Travis CI is OK most of the time. Still, CircleCI has some advantages: arbitrary Docker images cool test summaries Arbitrary Docker images Compared to Travis CI, CircleCI allows the users to use any docker images. For example, my WIP package which provides DBI-compatible interface to Redash uses these images: docker: - image: rocker/tidyverse:latest - image: redis:3. ... Read more

Introduction to gghighlight: Highlight ggplot's Lines and Points with Predicates

October 6, 2017

Suppose we have a data that has too many series like this: set.seed(2) d <- purrr::map_dfr( letters, ~ data.frame(idx = 1:400, value = cumsum(runif(400, -1, 1)), type = ., stringsAsFactors = FALSE)) For such data, it is almost impossible to identify a series by its colour as their differences are so subtle. library(ggplot2) ggplot(d) + geom_line(aes(idx, value, colour = type)) Highlight lines with ggplot2 + dplyr So, I am motivated to filter data and map colour only on that, using dplyr: ... Read more

About

July 15, 2017

Hi! I’m Hiroaki Yutani. This blog is where I struggle to learn about R (and improve my poor English). I belong to Hoxo-m Inc., a group of R-enthusiasts in Japan. My interests are mainly focused on data visualization, data manipulation and web APIs. I maintain several R packages: datadogr: R Client for Datadog API kntnr: R Client for kintone API qiitr: R Interface to Qiita API estatapi: R Interface to e-Stat API, the one-stop service for official statistics of the Japanese government kokudosuuchi: R Interface to Kokudo Suuchi API, the GIS data service of the Japanese government