diff --git a/.Rbuildignore b/.Rbuildignore index 1ca3261..ba06bb2 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -3,3 +3,4 @@ ^Meta$ ^LICENSE\.md$ ^data-raw$ +^doc$ diff --git a/.gitignore b/.gitignore index ea4f7f9..5e3d88b 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ inst/doc Meta doc/* /Meta/ +/doc/ diff --git a/DESCRIPTION b/DESCRIPTION index ce5042f..adcceba 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -38,11 +38,12 @@ Imports: tibble (>= 2.1.3), tidyr (>= 1.0.0) Suggests: + knitr, rmarkdown, testthat, usethis VignetteBuilder: - rmarkdown + knitr Encoding: UTF-8 LazyData: true RoxygenNote: 7.2.3 diff --git a/doc/tntp-style-plots.R b/doc/tntp-style-plots.R index 1ea5de3..f3fde07 100644 --- a/doc/tntp-style-plots.R +++ b/doc/tntp-style-plots.R @@ -1,4 +1,4 @@ -## ---- include = FALSE--------------------------------------------------------- +## ----include = FALSE---------------------------------------------------------- knitr::opts_chunk$set( collapse = TRUE, comment = "#>" @@ -8,142 +8,156 @@ knitr::opts_chunk$set( library(tntpr) # Load packages - first pacman, installing if necessary, then others -if (!require("pacman")) install.packages("pacman"); library(pacman) +if (!require("pacman")) install.packages("pacman") +library(pacman) p_load(devtools, tidyverse, knitr) if (!require("patchwork")) devtools::install_github("thomasp85/patchwork") ## ----knitr_options, include = FALSE------------------------------------------- knitr::opts_chunk$set(collapse = TRUE, comment = "#>") knitr::opts_chunk$set(error = TRUE) -knitr::opts_chunk$set(out.width='750px', dpi = 300) +knitr::opts_chunk$set(out.width = "750px", dpi = 300) knitr::opts_chunk$set(dev = "png", fig.width = 8, fig.height = 4.8889, dpi = 300) ## ----sample_datasets, include=FALSE------------------------------------------- - -performance_data <- data.frame(teacher_experience = c(rep("0-3 years ", 5), rep("4-6 years", 4), rep("7+ years", 4)), - y1_teacher_performance = sample(0:100,size = 13,rep=TRUE), - y2_teacher_performance = sample(0:100,size = 13,rep=TRUE)) %>% - mutate(y1_performance_quartile = ntile(x = y1_teacher_performance,n = 4)) - -survey_question <- data.frame(question = c(rep("To what extent do you \nagree with ...", 100)), - answer = sample(1:5, size = 100,rep=TRUE)) +performance_data <- data.frame( + teacher_experience = c(rep("0-3 years ", 5), rep("4-6 years", 4), rep("7+ years", 4)), + y1_teacher_performance = sample(0:100, size = 13, rep = TRUE), + y2_teacher_performance = sample(0:100, size = 13, rep = TRUE) +) %>% + mutate(y1_performance_quartile = ntile(x = y1_teacher_performance, n = 4)) + +survey_question <- data.frame( + question = c(rep("To what extent do you \nagree with ...", 100)), + answer = sample(1:5, size = 100, rep = TRUE) +) ## ----theme_tntp, echo=FALSE, warning=FALSE------------------------------------ - ex_plot_default <- performance_data %>% ggplot(aes(factor(teacher_experience))) + geom_bar() + - labs(title = "default", - subtitle = "Subtitle", - x = "x label", - y = "y label", - caption = "caption") + labs( + title = "default", + subtitle = "Subtitle", + x = "x label", + y = "y label", + caption = "caption" + ) ex_plot_theme_tntp <- performance_data %>% ggplot(aes(factor(teacher_experience))) + geom_bar() + - labs(title = "theme_tntp()", - subtitle = "Subtitle", - x = "x label", - y = "y label", - caption = "caption") + + labs( + title = "theme_tntp()", + subtitle = "Subtitle", + x = "x label", + y = "y label", + caption = "caption" + ) + theme_tntp() ex_plot_theme_tntp_2018 <- performance_data %>% ggplot(aes(factor(teacher_experience))) + geom_bar() + - labs(title = "theme_tntp_2018()", - subtitle = "Subtitle", - x = "x label", - y = "y label", - caption = "caption") + + labs( + title = "theme_tntp_2018()", + subtitle = "Subtitle", + x = "x label", + y = "y label", + caption = "caption" + ) + theme_tntp_2018() - -## ---- echo=FALSE, warning=FALSE, fig.width=7---------------------------------- +## ----echo=FALSE, warning=FALSE, fig.width=7----------------------------------- ex_plot_default -## ---- echo=FALSE, warning=FALSE, fig.width=7---------------------------------- +## ----echo=FALSE, warning=FALSE, fig.width=7----------------------------------- ex_plot_theme_tntp -## ---- echo=FALSE, warning=FALSE, fig.width=7---------------------------------- +## ----echo=FALSE, warning=FALSE, fig.width=7----------------------------------- ex_plot_theme_tntp_2018 ## ----plot_color_palette, include = FALSE-------------------------------------- - -# This function is for displaying color palettes -plot_color_palette <- function(dat, title = ""){ - dat %>% - as.data.frame() %>% - rownames_to_column() %>% - set_names(c("labels", "hex")) %>% - mutate(row = row_number()) %>% - ggplot(aes(x = row, y = 1, fill = hex)) + - geom_bar(stat = "identity") + - geom_text(aes(label = paste0(labels, " (", hex, ")")), position = position_stack(vjust = 0.5), color = "white") + - scale_fill_identity() + - coord_flip() + - labs(title = title, - x = NULL, - y = NULL) + - theme_tntp_2018() + - theme(axis.text = element_blank(), - panel.grid = element_blank()) +# This function is for displaying color palettes +plot_color_palette <- function(dat, title = "") { + dat %>% + as.data.frame() %>% + rownames_to_column() %>% + set_names(c("labels", "hex")) %>% + mutate(row = row_number()) %>% + ggplot(aes(x = row, y = 1, fill = hex)) + + geom_bar(stat = "identity") + + geom_text(aes(label = paste0(labels, " (", hex, ")")), position = position_stack(vjust = 0.5), color = "white") + + scale_fill_identity() + + coord_flip() + + labs( + title = title, + x = NULL, + y = NULL + ) + + theme_tntp_2018() + + theme( + axis.text = element_blank(), + panel.grid = element_blank() + ) } - ## ----------------------------------------------------------------------------- palette_tntp("dark_blue") -## ---- fig.height= 12, fig.width=5, warning=FALSE, echo = FALSE---------------- +## ----fig.height= 12, fig.width=5, warning=FALSE, echo = FALSE----------------- # A one-off function to plot color palettes, see code above if curious plot_color_palette(tntpr::colors_tntp, title = "palette_tntp colors") -## ---- fig.height= 12, fig.width=7, warning=FALSE, echo = FALSE---------------- - +## ----fig.height= 12, fig.width=7, warning=FALSE, echo = FALSE----------------- palettes <- c("default", "likert_4pt", "likert_5pt", "likert_6pt", "likert_orange_to_green_4pt", "likert_orange_to_green_5pt", "likert_orange_to_green_6pt") -palette_plots <- map(palettes, palette_tntp_scales) %>% +palette_plots <- map(palettes, palette_tntp_scales) %>% map2(palettes, plot_color_palette) palette_plots[[1]] + (palette_plots[[2]] + palette_plots[[3]] + palette_plots[[4]]) + palette_plots[[5]] + palette_plots[[6]] + palette_plots[[7]] + plot_layout(ncol = 1) - -## ---- fig.width=7, fig.length=5, warning=FALSE, echo=TRUE--------------------- +## ----fig.width=7, fig.length=5, warning=FALSE, echo=TRUE---------------------- performance_data %>% ggplot(aes(factor(teacher_experience), fill = factor(y1_performance_quartile))) + - geom_bar(position = position_fill()) + - labs(title = "Title", - subtitle = "Subtitle", - x = "x label", - y = "y label", - fill = "fill", - caption = "caption") + + geom_bar(position = position_fill()) + + labs( + title = "Title", + subtitle = "Subtitle", + x = "x label", + y = "y label", + fill = "fill", + caption = "caption" + ) + theme_tntp_2018() + scale_fill_tntp() -## ---- fig.width=7, fig.length=5, warning=FALSE, echo=TRUE--------------------- -performance_data %>% - ggplot(aes(x = y1_teacher_performance, y = y2_teacher_performance, color = factor(teacher_experience))) + - geom_point(size = 2) + - labs(title = "Title", - subtitle = "Subtitle", - x = "x label", - y = "y label", - fill = "fill", - caption = "caption") + - theme_tntp_2018() + - scale_color_tntp() - -## ---- fig.width=7, fig.length=5, warning=FALSE, echo = TRUE------------------- +## ----fig.width=7, fig.length=5, warning=FALSE, echo=TRUE---------------------- +performance_data %>% + ggplot(aes(x = y1_teacher_performance, y = y2_teacher_performance, color = factor(teacher_experience))) + + geom_point(size = 2) + + labs( + title = "Title", + subtitle = "Subtitle", + x = "x label", + y = "y label", + fill = "fill", + caption = "caption" + ) + + theme_tntp_2018() + + scale_color_tntp() + +## ----fig.width=7, fig.length=5, warning=FALSE, echo = TRUE-------------------- survey_question %>% ggplot(aes(factor(question), fill = factor(answer))) + geom_bar(position = position_fill()) + - labs(title = "Title", - subtitle = "Subtitle", - x = "x label", - y = "y label", - caption = "caption") + - theme_tntp_2018() + + labs( + title = "Title", + subtitle = "Subtitle", + x = "x label", + y = "y label", + caption = "caption" + ) + + theme_tntp_2018() + scale_fill_tntp(palette = "likert_5pt") diff --git a/doc/tntp-style-plots.Rmd b/doc/tntp-style-plots.Rmd index 9f3046b..552b7c6 100644 --- a/doc/tntp-style-plots.Rmd +++ b/doc/tntp-style-plots.Rmd @@ -18,7 +18,8 @@ knitr::opts_chunk$set( library(tntpr) # Load packages - first pacman, installing if necessary, then others -if (!require("pacman")) install.packages("pacman"); library(pacman) +if (!require("pacman")) install.packages("pacman") +library(pacman) p_load(devtools, tidyverse, knitr) if (!require("patchwork")) devtools::install_github("thomasp85/patchwork") ``` @@ -26,19 +27,22 @@ if (!require("patchwork")) devtools::install_github("thomasp85/patchwork") ```{r knitr_options, include = FALSE} knitr::opts_chunk$set(collapse = TRUE, comment = "#>") knitr::opts_chunk$set(error = TRUE) -knitr::opts_chunk$set(out.width='750px', dpi = 300) +knitr::opts_chunk$set(out.width = "750px", dpi = 300) knitr::opts_chunk$set(dev = "png", fig.width = 8, fig.height = 4.8889, dpi = 300) ``` ```{r sample_datasets, include=FALSE} - -performance_data <- data.frame(teacher_experience = c(rep("0-3 years ", 5), rep("4-6 years", 4), rep("7+ years", 4)), - y1_teacher_performance = sample(0:100,size = 13,rep=TRUE), - y2_teacher_performance = sample(0:100,size = 13,rep=TRUE)) %>% - mutate(y1_performance_quartile = ntile(x = y1_teacher_performance,n = 4)) - -survey_question <- data.frame(question = c(rep("To what extent do you \nagree with ...", 100)), - answer = sample(1:5, size = 100,rep=TRUE)) +performance_data <- data.frame( + teacher_experience = c(rep("0-3 years ", 5), rep("4-6 years", 4), rep("7+ years", 4)), + y1_teacher_performance = sample(0:100, size = 13, rep = TRUE), + y2_teacher_performance = sample(0:100, size = 13, rep = TRUE) +) %>% + mutate(y1_performance_quartile = ntile(x = y1_teacher_performance, n = 4)) + +survey_question <- data.frame( + question = c(rep("To what extent do you \nagree with ...", 100)), + answer = sample(1:5, size = 100, rep = TRUE) +) ``` @@ -47,36 +51,40 @@ survey_question <- data.frame(question = c(rep("To what extent do you \nagree wi tntpr now has two ggplot2 themes; the classic `theme_tntp()`, and the updated `theme_tntp_2018()`. ```{r theme_tntp, echo=FALSE, warning=FALSE} - ex_plot_default <- performance_data %>% ggplot(aes(factor(teacher_experience))) + geom_bar() + - labs(title = "default", - subtitle = "Subtitle", - x = "x label", - y = "y label", - caption = "caption") + labs( + title = "default", + subtitle = "Subtitle", + x = "x label", + y = "y label", + caption = "caption" + ) ex_plot_theme_tntp <- performance_data %>% ggplot(aes(factor(teacher_experience))) + geom_bar() + - labs(title = "theme_tntp()", - subtitle = "Subtitle", - x = "x label", - y = "y label", - caption = "caption") + + labs( + title = "theme_tntp()", + subtitle = "Subtitle", + x = "x label", + y = "y label", + caption = "caption" + ) + theme_tntp() ex_plot_theme_tntp_2018 <- performance_data %>% ggplot(aes(factor(teacher_experience))) + geom_bar() + - labs(title = "theme_tntp_2018()", - subtitle = "Subtitle", - x = "x label", - y = "y label", - caption = "caption") + + labs( + title = "theme_tntp_2018()", + subtitle = "Subtitle", + x = "x label", + y = "y label", + caption = "caption" + ) + theme_tntp_2018() - ``` ```{r, echo=FALSE, warning=FALSE, fig.width=7} @@ -94,27 +102,29 @@ ex_plot_theme_tntp_2018 ### palette_tntp() gives you access to TNTP-style colors: ```{r plot_color_palette, include = FALSE} - -# This function is for displaying color palettes -plot_color_palette <- function(dat, title = ""){ - dat %>% - as.data.frame() %>% - rownames_to_column() %>% - set_names(c("labels", "hex")) %>% - mutate(row = row_number()) %>% - ggplot(aes(x = row, y = 1, fill = hex)) + - geom_bar(stat = "identity") + - geom_text(aes(label = paste0(labels, " (", hex, ")")), position = position_stack(vjust = 0.5), color = "white") + - scale_fill_identity() + - coord_flip() + - labs(title = title, - x = NULL, - y = NULL) + - theme_tntp_2018() + - theme(axis.text = element_blank(), - panel.grid = element_blank()) +# This function is for displaying color palettes +plot_color_palette <- function(dat, title = "") { + dat %>% + as.data.frame() %>% + rownames_to_column() %>% + set_names(c("labels", "hex")) %>% + mutate(row = row_number()) %>% + ggplot(aes(x = row, y = 1, fill = hex)) + + geom_bar(stat = "identity") + + geom_text(aes(label = paste0(labels, " (", hex, ")")), position = position_stack(vjust = 0.5), color = "white") + + scale_fill_identity() + + coord_flip() + + labs( + title = title, + x = NULL, + y = NULL + ) + + theme_tntp_2018() + + theme( + axis.text = element_blank(), + panel.grid = element_blank() + ) } - ``` You can still use palette_tntp the way you used to... @@ -142,14 +152,12 @@ The `palette_tntp_scales()` function provides access to 5 TNTP color scales: ```{r, fig.height= 12, fig.width=7, warning=FALSE, echo = FALSE} - palettes <- c("default", "likert_4pt", "likert_5pt", "likert_6pt", "likert_orange_to_green_4pt", "likert_orange_to_green_5pt", "likert_orange_to_green_6pt") -palette_plots <- map(palettes, palette_tntp_scales) %>% +palette_plots <- map(palettes, palette_tntp_scales) %>% map2(palettes, plot_color_palette) palette_plots[[1]] + (palette_plots[[2]] + palette_plots[[3]] + palette_plots[[4]]) + palette_plots[[5]] + palette_plots[[6]] + palette_plots[[7]] + plot_layout(ncol = 1) - ``` ### `scale_fill_tntp()` and `scale_color_tntp()` @@ -159,29 +167,33 @@ Supply TNTP-palette scales for filling and coloring. ```{r, fig.width=7, fig.length=5, warning=FALSE, echo=TRUE} performance_data %>% ggplot(aes(factor(teacher_experience), fill = factor(y1_performance_quartile))) + - geom_bar(position = position_fill()) + - labs(title = "Title", - subtitle = "Subtitle", - x = "x label", - y = "y label", - fill = "fill", - caption = "caption") + + geom_bar(position = position_fill()) + + labs( + title = "Title", + subtitle = "Subtitle", + x = "x label", + y = "y label", + fill = "fill", + caption = "caption" + ) + theme_tntp_2018() + scale_fill_tntp() ``` ```{r, fig.width=7, fig.length=5, warning=FALSE, echo=TRUE} -performance_data %>% - ggplot(aes(x = y1_teacher_performance, y = y2_teacher_performance, color = factor(teacher_experience))) + - geom_point(size = 2) + - labs(title = "Title", - subtitle = "Subtitle", - x = "x label", - y = "y label", - fill = "fill", - caption = "caption") + - theme_tntp_2018() + - scale_color_tntp() +performance_data %>% + ggplot(aes(x = y1_teacher_performance, y = y2_teacher_performance, color = factor(teacher_experience))) + + geom_point(size = 2) + + labs( + title = "Title", + subtitle = "Subtitle", + x = "x label", + y = "y label", + fill = "fill", + caption = "caption" + ) + + theme_tntp_2018() + + scale_color_tntp() ``` @@ -190,11 +202,13 @@ You can specify which color palette you want to use. survey_question %>% ggplot(aes(factor(question), fill = factor(answer))) + geom_bar(position = position_fill()) + - labs(title = "Title", - subtitle = "Subtitle", - x = "x label", - y = "y label", - caption = "caption") + - theme_tntp_2018() + + labs( + title = "Title", + subtitle = "Subtitle", + x = "x label", + y = "y label", + caption = "caption" + ) + + theme_tntp_2018() + scale_fill_tntp(palette = "likert_5pt") ``` diff --git a/doc/tntp-style-plots.html b/doc/tntp-style-plots.html index 99b92df..6e92881 100644 --- a/doc/tntp-style-plots.html +++ b/doc/tntp-style-plots.html @@ -352,8 +352,8 @@

ggplot Themes

palette_tntp() gives you access to TNTP-style colors:

You can still use palette_tntp the way you used to…

-
palette_tntp("dark_blue")
-#> [1] "#00355F"
+
palette_tntp("dark_blue")
+#> [1] "#00355F"

… but now you have a larger selection of colors.

The palette_tntp_scales() function provides access to 5 @@ -377,42 +377,48 @@

palette_tntp() gives you access to TNTP-style colors:

scale_fill_tntp() and scale_color_tntp()

Supply TNTP-palette scales for filling and coloring.

-
performance_data %>%
-  ggplot(aes(factor(teacher_experience), fill = factor(y1_performance_quartile))) +
-    geom_bar(position = position_fill()) +
-    labs(title = "Title",
-         subtitle = "Subtitle",
-         x = "x label",
-         y = "y label",
-         fill = "fill",
-         caption = "caption") +
-  theme_tntp_2018() +
-  scale_fill_tntp()
-

-
performance_data %>% 
-  ggplot(aes(x = y1_teacher_performance, y = y2_teacher_performance, color = factor(teacher_experience))) + 
-    geom_point(size = 2) + 
-    labs(title = "Title",
-       subtitle = "Subtitle",
-       x = "x label",
-       y = "y label",
-       fill = "fill",
-       caption = "caption") + 
-    theme_tntp_2018() + 
-    scale_color_tntp()
-

+
performance_data %>%
+  ggplot(aes(factor(teacher_experience), fill = factor(y1_performance_quartile))) +
+  geom_bar(position = position_fill()) +
+  labs(
+    title = "Title",
+    subtitle = "Subtitle",
+    x = "x label",
+    y = "y label",
+    fill = "fill",
+    caption = "caption"
+  ) +
+  theme_tntp_2018() +
+  scale_fill_tntp()
+

+
performance_data %>%
+  ggplot(aes(x = y1_teacher_performance, y = y2_teacher_performance, color = factor(teacher_experience))) +
+  geom_point(size = 2) +
+  labs(
+    title = "Title",
+    subtitle = "Subtitle",
+    x = "x label",
+    y = "y label",
+    fill = "fill",
+    caption = "caption"
+  ) +
+  theme_tntp_2018() +
+  scale_color_tntp()
+

You can specify which color palette you want to use.

-
survey_question %>%
-  ggplot(aes(factor(question), fill = factor(answer))) +
-  geom_bar(position = position_fill()) +
-  labs(title = "Title",
-       subtitle = "Subtitle",
-       x = "x label",
-       y = "y label",
-       caption = "caption") +
-  theme_tntp_2018() + 
-  scale_fill_tntp(palette = "likert_5pt")
-

+
survey_question %>%
+  ggplot(aes(factor(question), fill = factor(answer))) +
+  geom_bar(position = position_fill()) +
+  labs(
+    title = "Title",
+    subtitle = "Subtitle",
+    x = "x label",
+    y = "y label",
+    caption = "caption"
+  ) +
+  theme_tntp_2018() +
+  scale_fill_tntp(palette = "likert_5pt")
+

diff --git a/doc/tntpr-introduction.R b/doc/tntpr-introduction.R index 01464a3..0f59c00 100644 --- a/doc/tntpr-introduction.R +++ b/doc/tntpr-introduction.R @@ -1,4 +1,4 @@ -## ---- include = FALSE--------------------------------------------------------- +## ----include = FALSE---------------------------------------------------------- knitr::opts_chunk$set( collapse = TRUE, comment = "#>" @@ -8,7 +8,7 @@ knitr::opts_chunk$set( library(tntpr) library(tidyverse) -## ---- include = FALSE--------------------------------------------------------- +## ----include = FALSE---------------------------------------------------------- library(tntpr) library(magrittr) library(ggplot2) @@ -22,26 +22,32 @@ palette_tntp("dark_blue", "orange", "light_gray") palette_tntp_scales(palette = "likert_5pt") ## ----scale_fill_tntp, fig.width=7, fig.align='center', warning=FALSE---------- - -data.frame(question = "To what extent do you agree...", - response = c(rep("Strongly disagree", 3), - rep("Disagree", 4), - rep("Somewhat disagree", 3), - rep("Somewhat agree", 4), - rep("Agree", 10), - rep("Strongly agree", 2))) %>% - mutate(response = response %>% factor(levels = rev(c("Strongly disagree", - "Disagree", - "Somewhat disagree", - "Somewhat agree", - "Agree", - "Strongly agree")))) %>% - ggplot(aes(question, fill = response)) + - geom_bar(position = position_fill()) + - theme_tntp_2018(axis_text = "Y", grid = FALSE) + - labs(x = NULL, y = NULL, - fill = "Response") + - coord_flip() + - scale_fill_tntp(palette = "likert_6pt") - +data.frame( + question = "To what extent do you agree...", + response = c( + rep("Strongly disagree", 3), + rep("Disagree", 4), + rep("Somewhat disagree", 3), + rep("Somewhat agree", 4), + rep("Agree", 10), + rep("Strongly agree", 2) + ) +) %>% + mutate(response = response %>% factor(levels = rev(c( + "Strongly disagree", + "Disagree", + "Somewhat disagree", + "Somewhat agree", + "Agree", + "Strongly agree" + )))) %>% + ggplot(aes(question, fill = response)) + + geom_bar(position = position_fill()) + + theme_tntp_2018(axis_text = "Y", grid = FALSE) + + labs( + x = NULL, y = NULL, + fill = "Response" + ) + + coord_flip() + + scale_fill_tntp(palette = "likert_6pt") diff --git a/doc/tntpr-introduction.Rmd b/doc/tntpr-introduction.Rmd index 0f37ef8..645fe8a 100644 --- a/doc/tntpr-introduction.Rmd +++ b/doc/tntpr-introduction.Rmd @@ -115,26 +115,32 @@ palette_tntp_scales(palette = "likert_5pt") You can use these scale palettes as fill or color aesthetics in ggplot with `scale_fill_tntp` and `scale_color_tntp`. ```{r scale_fill_tntp, fig.width=7, fig.align='center', warning=FALSE} - -data.frame(question = "To what extent do you agree...", - response = c(rep("Strongly disagree", 3), - rep("Disagree", 4), - rep("Somewhat disagree", 3), - rep("Somewhat agree", 4), - rep("Agree", 10), - rep("Strongly agree", 2))) %>% - mutate(response = response %>% factor(levels = rev(c("Strongly disagree", - "Disagree", - "Somewhat disagree", - "Somewhat agree", - "Agree", - "Strongly agree")))) %>% - ggplot(aes(question, fill = response)) + - geom_bar(position = position_fill()) + - theme_tntp_2018(axis_text = "Y", grid = FALSE) + - labs(x = NULL, y = NULL, - fill = "Response") + - coord_flip() + - scale_fill_tntp(palette = "likert_6pt") - +data.frame( + question = "To what extent do you agree...", + response = c( + rep("Strongly disagree", 3), + rep("Disagree", 4), + rep("Somewhat disagree", 3), + rep("Somewhat agree", 4), + rep("Agree", 10), + rep("Strongly agree", 2) + ) +) %>% + mutate(response = response %>% factor(levels = rev(c( + "Strongly disagree", + "Disagree", + "Somewhat disagree", + "Somewhat agree", + "Agree", + "Strongly agree" + )))) %>% + ggplot(aes(question, fill = response)) + + geom_bar(position = position_fill()) + + theme_tntp_2018(axis_text = "Y", grid = FALSE) + + labs( + x = NULL, y = NULL, + fill = "Response" + ) + + coord_flip() + + scale_fill_tntp(palette = "likert_6pt") ``` diff --git a/doc/tntpr-introduction.html b/doc/tntpr-introduction.html index 5a4c8ce..034de59 100644 --- a/doc/tntpr-introduction.html +++ b/doc/tntpr-introduction.html @@ -437,40 +437,47 @@

TNTP colors

You can access the official TNTP-branded colors using palette_tntp(). This will return a vector with hex code for our colors:

-
palette_tntp("dark_blue", "orange", "light_gray")
-#> [1] "#00355F" "#EA8835" "#C1C2C4"
+
palette_tntp("dark_blue", "orange", "light_gray")
+#> [1] "#00355F" "#EA8835" "#C1C2C4"

Or you can select a specific TNTP palette ("default", "colors_tntp_classic", "likert_4pt", "likert_5pt", or "likert_6pt") with palette_tntp_scales and return a vector with hex codes for that TNTP palette.

-
palette_tntp_scales(palette = "likert_5pt")
-#>   dark_blue medium_blue  light_grey    orange_3    orange_4 
-#>   "#00355F"   "#00A4C7"   "#C1C2C4"   "#EA8835"   "#BC5A07"
+
palette_tntp_scales(palette = "likert_5pt")
+#>   dark_blue medium_blue  light_grey    orange_3    orange_4 
+#>   "#00355F"   "#00A4C7"   "#C1C2C4"   "#EA8835"   "#BC5A07"

You can use these scale palettes as fill or color aesthetics in ggplot with scale_fill_tntp and scale_color_tntp.

-

-data.frame(question = "To what extent do you agree...", 
-           response = c(rep("Strongly disagree", 3), 
-                        rep("Disagree", 4), 
-                        rep("Somewhat disagree", 3), 
-                        rep("Somewhat agree", 4),  
-                        rep("Agree", 10), 
-                        rep("Strongly agree", 2))) %>% 
-  mutate(response = response %>% factor(levels = rev(c("Strongly disagree", 
-                                                   "Disagree", 
-                                                   "Somewhat disagree", 
-                                                   "Somewhat agree",
-                                                   "Agree", 
-                                                   "Strongly agree")))) %>% 
-  ggplot(aes(question, fill = response)) + 
-    geom_bar(position = position_fill()) + 
-    theme_tntp_2018(axis_text = "Y", grid = FALSE) + 
-    labs(x = NULL, y = NULL, 
-         fill = "Response") + 
-    coord_flip() + 
-    scale_fill_tntp(palette = "likert_6pt")
+
data.frame(
+  question = "To what extent do you agree...",
+  response = c(
+    rep("Strongly disagree", 3),
+    rep("Disagree", 4),
+    rep("Somewhat disagree", 3),
+    rep("Somewhat agree", 4),
+    rep("Agree", 10),
+    rep("Strongly agree", 2)
+  )
+) %>%
+  mutate(response = response %>% factor(levels = rev(c(
+    "Strongly disagree",
+    "Disagree",
+    "Somewhat disagree",
+    "Somewhat agree",
+    "Agree",
+    "Strongly agree"
+  )))) %>%
+  ggplot(aes(question, fill = response)) +
+  geom_bar(position = position_fill()) +
+  theme_tntp_2018(axis_text = "Y", grid = FALSE) +
+  labs(
+    x = NULL, y = NULL,
+    fill = "Response"
+  ) +
+  coord_flip() +
+  scale_fill_tntp(palette = "likert_6pt")

diff --git a/vignettes/.gitignore b/vignettes/.gitignore new file mode 100644 index 0000000..097b241 --- /dev/null +++ b/vignettes/.gitignore @@ -0,0 +1,2 @@ +*.html +*.R diff --git a/vignettes/date_to_sy_worked_example.Rmd b/vignettes/date_to_sy_worked_example.Rmd index aae81bc..b160c26 100644 --- a/vignettes/date_to_sy_worked_example.Rmd +++ b/vignettes/date_to_sy_worked_example.Rmd @@ -1,7 +1,10 @@ --- title: 'Worked Example: `tntpr::date_to_sy`' -output: - github_document +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{date_to_sy} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} --- diff --git a/vignettes/factorizing_a_dataset.Rmd b/vignettes/factorizing_a_dataset.Rmd index 7957999..e56f55d 100644 --- a/vignettes/factorizing_a_dataset.Rmd +++ b/vignettes/factorizing_a_dataset.Rmd @@ -1,8 +1,10 @@ --- title: "Factorizing a survey dataset" -date: '`r Sys.Date()`' -output: - github_document +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{factorizing-a-dataset} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} --- diff --git a/vignettes/tntp-style-plots.Rmd b/vignettes/tntp-style-plots.Rmd index 4dafdd2..552b7c6 100644 --- a/vignettes/tntp-style-plots.Rmd +++ b/vignettes/tntp-style-plots.Rmd @@ -1,6 +1,6 @@ --- title: "tntp-style-plots" -output: github_document +output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{tntp-style-plots} %\VignetteEngine{knitr::rmarkdown} diff --git a/vignettes/tntpr-introduction.Rmd b/vignettes/tntpr-introduction.Rmd index a0a7fe2..645fe8a 100644 --- a/vignettes/tntpr-introduction.Rmd +++ b/vignettes/tntpr-introduction.Rmd @@ -1,8 +1,8 @@ --- title: "tntpr-introduction" -output: github_document +output: rmarkdown::html_vignette vignette: > - %\VignetteIndexEntry{tntp-style-plots} + %\VignetteIndexEntry{tntpr-introduction} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} ---