| #' ) | #' ) | ||||
| #' | #' | ||||
| #' library(ggplot2) | #' library(ggplot2) | ||||
| #' ggplot(iris) + | |||||
| #' aes(Petal.Length, Petal.Width) + | |||||
| #' ggplot(mpg) + | |||||
| #' aes(cty, hwy) + | |||||
| #' geom_point() + | #' geom_point() + | ||||
| #' ggtitle("Yet another Iris plot") + | |||||
| #' ggtitle("Fuel Efficiency of Various Cars") + | |||||
| #' theme_xaringan() | #' theme_xaringan() | ||||
| #' } | #' } | ||||
| #' @return A ggplot2 theme | #' @return A ggplot2 theme | ||||
| #' ) | #' ) | ||||
| #' | #' | ||||
| #' library(ggplot2) | #' library(ggplot2) | ||||
| #' ggplot(iris) + | |||||
| #' aes(Petal.Length, Petal.Width) + | |||||
| #' ggplot(mpg) + | |||||
| #' aes(cty, hwy) + | |||||
| #' geom_point() + | #' geom_point() + | ||||
| #' ggtitle("Yet another Iris plot") + | |||||
| #' ggtitle("Fuel Efficiency of Various Cars") + | |||||
| #' # themed to match the inverse slides: teal background with dark blue text | #' # themed to match the inverse slides: teal background with dark blue text | ||||
| #' theme_xaringan_inverse() | #' theme_xaringan_inverse() | ||||
| #' } | #' } | ||||
| #' if (has_ggplot2) { | #' if (has_ggplot2) { | ||||
| #' library(ggplot2) | #' library(ggplot2) | ||||
| #' | #' | ||||
| #' plot1 <- ggplot(iris) + | |||||
| #' aes(Petal.Length, Petal.Width) + | |||||
| #' plot1 <- ggplot(mpg) + | |||||
| #' aes(cty, hwy) + | |||||
| #' geom_point() + | #' geom_point() + | ||||
| #' theme_xaringan_base( | #' theme_xaringan_base( | ||||
| #' text_color = "#602f6b", # imperial | #' text_color = "#602f6b", # imperial | ||||
| #' set_ggplot_defaults = TRUE | #' set_ggplot_defaults = TRUE | ||||
| #' ) + | #' ) + | ||||
| #' labs( | #' labs( | ||||
| #' title = "Basic Iris Plot", | |||||
| #' title = "Fuel Efficiency of Various Cars", | |||||
| #' subtitle = "+ theme_xaringan_base()", | #' subtitle = "+ theme_xaringan_base()", | ||||
| #' caption = "xaringanthemer" | #' caption = "xaringanthemer" | ||||
| #' ) | #' ) | ||||
| #' | #' | ||||
| #' print(plot1) | #' print(plot1) | ||||
| #' | #' | ||||
| #' plot2 <- ggplot(iris) + | |||||
| #' aes(Sepal.Width) + | |||||
| #' geom_histogram(binwidth = 0.1) + | |||||
| #' plot2 <- ggplot(mpg) + | |||||
| #' aes(hwy) + | |||||
| #' geom_histogram(binwidth = 2) + | |||||
| #' theme_xaringan_base( | #' theme_xaringan_base( | ||||
| #' text_color = "#a8a9c8", # light purple | #' text_color = "#a8a9c8", # light purple | ||||
| #' background_color = "#303163", # deep slate purple | #' background_color = "#303163", # deep slate purple | ||||
| #' set_ggplot_defaults = TRUE | #' set_ggplot_defaults = TRUE | ||||
| #' ) + | #' ) + | ||||
| #' labs( | #' labs( | ||||
| #' title = "Basic Iris Plot", | |||||
| #' title = "Highway Fuel Efficiency", | |||||
| #' subtitle = "+ theme_xaringan_base()", | #' subtitle = "+ theme_xaringan_base()", | ||||
| #' caption = "xaringanthemer" | #' caption = "xaringanthemer" | ||||
| #' ) | #' ) |
| If you want to generate a table, make sure it is in the HTML format (instead of Markdown or other formats), e.g., | If you want to generate a table, make sure it is in the HTML format (instead of Markdown or other formats), e.g., | ||||
| ```{r} | ```{r} | ||||
| knitr::kable(head(iris), format = 'html') | |||||
| knitr::kable(head(mtcars), format = 'html') | |||||
| ``` | ``` | ||||
| --- | --- | ||||
| ```{r eval=require('DT'), tidy=FALSE} | ```{r eval=require('DT'), tidy=FALSE} | ||||
| DT::datatable( | DT::datatable( | ||||
| head(iris, 10), | |||||
| mtcars[1:6, 1:6], | |||||
| fillContainer = FALSE, options = list(pageLength = 8) | fillContainer = FALSE, options = list(pageLength = 8) | ||||
| ) | ) | ||||
| ``` | ``` |
| ) | ) | ||||
| library(ggplot2) | library(ggplot2) | ||||
| ggplot(iris) + | |||||
| aes(Petal.Length, Petal.Width) + | |||||
| ggplot(mpg) + | |||||
| aes(cty, hwy) + | |||||
| geom_point() + | geom_point() + | ||||
| ggtitle("Yet another Iris plot") + | |||||
| ggtitle("Fuel Efficiency of Various Cars") + | |||||
| theme_xaringan() | theme_xaringan() | ||||
| } | } | ||||
| } | } |
| if (has_ggplot2) { | if (has_ggplot2) { | ||||
| library(ggplot2) | library(ggplot2) | ||||
| plot1 <- ggplot(iris) + | |||||
| aes(Petal.Length, Petal.Width) + | |||||
| plot1 <- ggplot(mpg) + | |||||
| aes(cty, hwy) + | |||||
| geom_point() + | geom_point() + | ||||
| theme_xaringan_base( | theme_xaringan_base( | ||||
| text_color = "#602f6b", # imperial | text_color = "#602f6b", # imperial | ||||
| set_ggplot_defaults = TRUE | set_ggplot_defaults = TRUE | ||||
| ) + | ) + | ||||
| labs( | labs( | ||||
| title = "Basic Iris Plot", | |||||
| title = "Fuel Efficiency of Various Cars", | |||||
| subtitle = "+ theme_xaringan_base()", | subtitle = "+ theme_xaringan_base()", | ||||
| caption = "xaringanthemer" | caption = "xaringanthemer" | ||||
| ) | ) | ||||
| print(plot1) | print(plot1) | ||||
| plot2 <- ggplot(iris) + | |||||
| aes(Sepal.Width) + | |||||
| geom_histogram(binwidth = 0.1) + | |||||
| plot2 <- ggplot(mpg) + | |||||
| aes(hwy) + | |||||
| geom_histogram(binwidth = 2) + | |||||
| theme_xaringan_base( | theme_xaringan_base( | ||||
| text_color = "#a8a9c8", # light purple | text_color = "#a8a9c8", # light purple | ||||
| background_color = "#303163", # deep slate purple | background_color = "#303163", # deep slate purple | ||||
| set_ggplot_defaults = TRUE | set_ggplot_defaults = TRUE | ||||
| ) + | ) + | ||||
| labs( | labs( | ||||
| title = "Basic Iris Plot", | |||||
| title = "Highway Fuel Efficiency", | |||||
| subtitle = "+ theme_xaringan_base()", | subtitle = "+ theme_xaringan_base()", | ||||
| caption = "xaringanthemer" | caption = "xaringanthemer" | ||||
| ) | ) |
| ) | ) | ||||
| library(ggplot2) | library(ggplot2) | ||||
| ggplot(iris) + | |||||
| aes(Petal.Length, Petal.Width) + | |||||
| ggplot(mpg) + | |||||
| aes(cty, hwy) + | |||||
| geom_point() + | geom_point() + | ||||
| ggtitle("Yet another Iris plot") + | |||||
| ggtitle("Fuel Efficiency of Various Cars") + | |||||
| # themed to match the inverse slides: teal background with dark blue text | # themed to match the inverse slides: teal background with dark blue text | ||||
| theme_xaringan_inverse() | theme_xaringan_inverse() | ||||
| } | } |