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

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

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