Skip to content

Instantly share code, notes, and snippets.

@bhive01
Last active September 15, 2016 22:14
Show Gist options
  • Save bhive01/8e4099a1b83ec325c252dc59716d87d5 to your computer and use it in GitHub Desktop.
Save bhive01/8e4099a1b83ec325c252dc59716d87d5 to your computer and use it in GitHub Desktop.
---
title: "testforcarson"
author: "Brandon Hurr"
date: "September 15, 2016"
output: html_document
---
```{r setup, eval = TRUE, echo = FALSE, warning = FALSE, message = FALSE, results='asis', out.width = 1000, out.height = 1000}
library(ggplot2)
library(dplyr)
library(plotly)
library(purrr)
library(tibble)
df <- tibble(Type = rep(c("A", "B"), 50), SubType = rep(c("Apple", "Banana", "Kiwifruit", "Watermelon"), 25), Value = runif(100) )
```
## Split with Purrr
```{r purrplot, eval = TRUE, echo = FALSE, warning = FALSE, message = FALSE, results='asis', out.width = 1000, out.height = 1000}
plotgroup <-
function(df) {
wType <-
df$Type[[1]]
gp <-
ggplot(df, aes(x = SubType, y = Value)) +
geom_point() +
labs(colour = "", title = paste(wType))
ggplotly(gp, tooltip = c("y", "colour")) %>% layout(hovermode = "closest")
}
df %>%
split(.$Type) %>%
map(~plotgroup(.)) %>%
htmltools::tagList()
```
## Faceted
```{r ggfaceted, eval = TRUE, echo = FALSE, warning = FALSE, message = FALSE, results='asis', out.width = 1000, out.height = 1000}
gf <-
ggplot(df, aes(x = SubType, y = Value)) +
geom_point() +
facet_grid(Type ~ .)
ggplotly(gf, tooltip = c("y", "colour")) %>% layout(hovermode = "closest")
```
@bhive01
Copy link
Author

bhive01 commented Sep 15, 2016

Prints $A and $B (which I don't actually want), but no plots. When run as an R script, plots are output to browser, but I want to embed them into an HTML file. It works when I facet instead of split with purrr

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