knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "README-" )
ggplot with the pipe
This package wraps most ggplot2
functions so they work with the pipe %>%
with minimal overhead (if noticeable).
You can install ggpipe from github with:
# install.packages("devtools") devtools::install_github("zeehio/ggpipe")
# as ggpipe wraps ggplot2 functions, do not use library(ggplot2) in your scripts library(ggpipe) ggplot(mtcars) %>% geom_point(aes(x = mpg, y = disp))
This package provides an additional unggplot()
function to get back the data
from the plot, so multiple plots could be generated on a single pipe:
iris_sepal_png <- "README-iris_sepal.png" iris_petal_png <- "README-iris_petal.png" iris %>% ggplot() %>% geom_point(aes(x = Sepal.Length, y = Sepal.Width, color = Species)) %>% ggsave(iris_sepal_png, height = 3, width = 5, dpi = 72) %>% unggplot() %>% ggplot() %>% geom_point(aes(x = Petal.Length, y = Petal.Width, color = Species)) %>% ggsave(iris_petal_png, height = 3, width = 5, dpi = 72) %>% unggplot() %>% head()
Plot the two figures:
knitr::include_graphics(iris_sepal_png) knitr::include_graphics(iris_petal_png)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.