Double dispatch of S3 method

September 17, 2018

When I tried to define an S3 class that contains multiple ggplot objects, I’ve faced the lessor-know mechanism of S3 method dispatch, double dispatch. Problem Take a look at this example. manyplot class contains many plots, and displays them nicely when printted. library(ggplot2) set.seed(100) d1 <- data.frame(x = 1:100, y = cumsum(runif(100))) d2 <- data.frame(x = 1:100, y = cumsum(runif(100))) plot_all <- function(...) { l <- lapply(list(...), function(d) ggplot(d, aes(x, y)) + geom_line()) l <- unname(l) class(l) <- "manyplot" l } print. ... Read more

gghighlight 0.1.0 Is Released!

July 4, 2018

gghighlight 0.1.0 is on CRAN now! New features As I’ve introduced on the previous post, gghighlight now can highlight any Geoms with gghighlight(). Since this function supersedes the previous functions, gghighlight_line() and gghighlight_point() are now deprecated. A Vignette One more small news is, gghighlight got an introductory vignette. This is basically the shorter version of the previous post: Introduction to gghighlight

Re-introduction to gghighlight: Highlight ggplot2 with Predicates

June 16, 2018

Half a year ago, I’ve introduced gghighlight package. I didn’t expect so much R people get interested in my package. Thanks for your attention! But, please forget about that gghighlight; gghighlight has become far more powerful and simple! So, let me re-introduce about gghighlight. (Note that this version of gghighlight is not yet on CRAN at the time of this writing. Please install by devtools::install_github("yutannihilation/gghighlight") for the time being) ... Read more

Plot geom_sf() On OpenStreetMap Tiles

June 9, 2018

mapview is a very nice package to explore an sf object. It can overlay sf object on the map images: nc <- sf::read_sf(system.file("shape/nc.shp", package="sf")) mapview::mapview(nc) But, how can I do this with ggplot2? (My friend told me mapview::mapshot() can generate a PNG, but I want to do this with ggplot2!) RTFM Before anything, I need to read Tile Usage Policy to use the OpenStreetMap tiles. For “Requirements” section, this is important: ... Read more

Anatomy of gghighlight

June 3, 2018

I’m overhauling my gghighlight package toward the upcoming release of ggplot2 2.3.0. I think I will introduce about the new gghighlight() soon, but before that, I want to write out the ideas behind gghighlight. Note that what I’ll write here contains few new things, as the basic idea is already covered by this great post: Plotting background data for groups with ggplot2 My post is mainly for organizing my thought, yet I hope someone find this useful :) ... Read more

ICYMI: Using rtweet Package Is Super Easy Now!

February 12, 2018

Since the version 0.6.0 (published on Nov 16, 2017), rtweet package no longer requires the users to create their own apps. Did you notice? I didn’t know this until the author, Michael W. Kearney, kindly answered to my silly question on GitHub. I really appreciate that he is always eager not only to maintain the code but also to communicate with lazy users like me. Then, I did a quick poll (sorry, in Japanese) about how well known is the fact. ... Read more

dplyr Doesn't Provide Full Support For S4 (For Now?)

February 12, 2018

I’ve seen sooo many (duplicated) issues on this topic were opened on dplyr’s repo and lubridate’s repo. For example, you cannot filter() intervals. Consider the data below: library(lubridate) #> Loading required package: methods #> #> Attaching package: 'lubridate' #> The following object is masked from 'package:base': #> #> date library(dplyr, warn.conflicts = FALSE) # some method of tibble() won't work for interval d <- data.frame( i = interval(ymd(10000101) + years(1:3 * 1000), ymd(10000102) + years(1:3 * 1000)), value = 1:3 ) d #> i value #> 1 2000-01-01 UTC--2000-01-02 UTC 1 #> 2 3000-01-01 UTC--3000-01-02 UTC 2 #> 3 4000-01-01 UTC--4000-01-02 UTC 3 Let’s select the second row by filter(). ... Read more

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: 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