Skip to content

Instantly share code, notes, and snippets.

@dill
Created February 20, 2016 20:23
Show Gist options
  • Save dill/9fca5140c44acf6051a9 to your computer and use it in GitHub Desktop.
Save dill/9fca5140c44acf6051a9 to your computer and use it in GitHub Desktop.
display R plots in iTerm2
library(ggplot2)
library(emoGG)
source("imgcat.R")
p <- ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) + geom_emoji(emoji="1f337")
imgcat(print(p))
# display your plots inline using imgcat witchcraft
# download imgcat from https://raw.githubusercontent.com/gnachman/iTerm2/master/tests/imgcat
# you need the beta version of iTerm2 to get this to work on Mac
# untested elsewhere
# David Lawrence Miller GPL 2016
imgcat <- function(plot_command){
fn <- tempfile(pattern = "file", tmpdir = tempdir(), fileext = "")
png(fn)
eval(quote(plot_command))
dev.off()
system2("imgcat", fn)
}
@dill
Copy link
Author

dill commented Feb 20, 2016

Results look like this!
screen shot 2016-02-20 at 15 21 45

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment