Last active
September 15, 2016 22:14
-
-
Save bhive01/8e4099a1b83ec325c252dc59716d87d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| 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") | |
| ``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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