From 6a80e9864fe5cc21d2825a4f056bef483679056f Mon Sep 17 00:00:00 2001 From: eivindhammers Date: Thu, 25 Apr 2024 11:51:18 +0200 Subject: [PATCH 1/3] Use Norad colors as default, tidy some of thecode --- DESCRIPTION | 2 +- R/ggnorad.R | 16 ++++++++-- R/palette_functions.R | 56 ++++++++++++--------------------- man/ggnorad.Rd | 13 +++++--- man/palette_gen_c.Rd | 2 +- man/scale_color_norad_binned.Rd | 2 +- man/scale_color_norad_c.Rd | 2 +- man/scale_fill_norad_binned.Rd | 2 +- man/scale_fill_norad_c.Rd | 2 +- 9 files changed, 48 insertions(+), 49 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 3c4fa9e..a0194ee 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -11,7 +11,7 @@ Description: Provides Norads colour palette and theme for creating ggplot2 graph License: MIT + file LICENSE Encoding: UTF-8 LazyData: true -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 Imports: curl, ggplot2, diff --git a/R/ggnorad.R b/R/ggnorad.R index 30748a0..deb47c3 100644 --- a/R/ggnorad.R +++ b/R/ggnorad.R @@ -1,10 +1,13 @@ -#' Wrapper function to load norad theme +#' Wrapper function to load Norad theme for ggplot2. +#' Also sets Norad's discrete and continuous color palettes as the default for the session. #' -#'@param style Plot style. One of "default", "biglight1", "biglight2", "bigdark". +#'@param style Plot style. One of "default", "biglight1", "biglight2", "bigdark", +#' "maplight", "mapdark", or "light" +#'@param norad_colors Logical. Should Norad's color palettes be set as the default for the session? Default is TRUE. #'@export #'@name ggnorad -ggnorad <- function(style = "default") { +ggnorad <- function(style = "default", norad_colors = TRUE) { showtext::showtext_auto() @@ -51,4 +54,11 @@ ggnorad <- function(style = "default") { } else if (style == "mapdark") { ggplot2::theme_set(theme_norad_map_dark()) } + + if (norad_colors == TRUE) { + options(ggplot2.discrete.colour = scale_color_norad) + options(ggplot2.discrete.fill = scale_fill_norad) + options(ggplot2.continuous.colour = scale_color_norad_c) + options(ggplot2.continuous.fill = scale_fill_norad_c) + } } diff --git a/R/palette_functions.R b/R/palette_functions.R index 0fcae78..314a253 100644 --- a/R/palette_functions.R +++ b/R/palette_functions.R @@ -94,22 +94,14 @@ norad_pal <- function(palette = "main", ...) { #' palette_gen <- function(palette = "main", direction = 1) { - function(n) { - if (n > length(norad_pal(palette))) warning("Not enough colors in this palette!") - else { - all_colors <- norad_pal(palette) - all_colors <- unname(unlist(all_colors)) - all_colors <- if (direction >= 0) all_colors else rev(all_colors) - color_list <- all_colors[1:n] - } } } @@ -121,17 +113,15 @@ palette_gen <- function(palette = "main", direction = 1) { #' @param ... Additional arguments passed to ggplot2::colorRampPalette() #' -palette_gen_c <- function(palette = "main", direction = 1, ...) { - +palette_gen_c <- function(palette = "greens", direction = 1, ...) { + if (!palette %in% c("greens", "browns", "purples")) { + stop("Only 'greens', 'browns', and 'purples' palettes are supported") + } pal <- norad_pal(palette) - pal <- if (direction >= 0) pal else rev(pal) - grDevices::colorRampPalette(pal, ...) - } - #' Discrete color scale constructor for Norad colors #' #' @param palette Character name of palette in norad_palettes @@ -142,8 +132,8 @@ palette_gen_c <- function(palette = "main", direction = 1, ...) { scale_color_norad <- function(palette = "main", direction = 1, ...) { ggplot2::discrete_scale( - "color", "norad", - palette_gen(palette, direction), + aesthetics = "color", + palette = palette_gen(palette, direction), ... ) } @@ -159,47 +149,47 @@ scale_color_norad <- function(palette = "main", direction = 1, ...) { scale_fill_norad <- function(palette = "main", direction = 1, ...) { ggplot2::discrete_scale( - "fill", "norad", - palette_gen(palette, direction), + aesthetics = "fill", + palette = palette_gen(palette, direction), ... ) } #' Continious color scale constructor for Norad colors #' -#' @param palette Character name of palette in norad_palettes +#' @param palette Character name of palette in norad_palettes. One of "greens", "browns", or "purples" #' @param direction Integer indicating whether the palette should be reversed #' @param ... Additional arguments passed to ggplot2::scale_fill_gradientn() #' @export #' scale_color_norad_c <- function(palette = "greens", direction = 1, ...) { - - pal <- palette_gen_c(palette = palette, direction = direction) - + pal <- palette_gen_c( + palette = palette, + direction = direction + ) ggplot2::scale_color_gradientn(colors = pal(256), ...) - } #' Continuous fill scale constructor for Norad colors #' -#' @param palette Character name of palette in norad_palettes +#' @param palette Character name of palette in norad_palettes. One of "greens", "browns", or "purples" #' @param direction Integer indicating whether the palette should be reversed #' @param ... Additional arguments passed to ggplot2::scale_fill_gradientn() #' @export #' scale_fill_norad_c <- function(palette = "greens", direction = 1, ...) { - - pal <- palette_gen_c(palette = palette, direction = direction) - + pal <- palette_gen_c( + palette = palette, + direction = direction + ) ggplot2::scale_fill_gradientn(colors = pal(256), ...) - } #' Binned fill scale constructor for Norad colors #' -#' @param palette Character name of palette in norad_palettes +#' @param palette Character name of palette in norad_palettes. One of "greens", "browns", or "purples" #' @param direction Integer indicating whether the palette should be reversed #' @param breaks How to break down continuous data into bins. Computed automatically by default. #' @param ... Additional arguments passed to ggplot2::scale_fill_steps() @@ -207,16 +197,13 @@ scale_fill_norad_c <- function(palette = "greens", direction = 1, ...) { #' scale_fill_norad_binned <- function(palette = "greens", direction = 1, breaks = waiver(), ...) { - pal <- norad_pal(palette) - ggplot2::scale_fill_steps(low = pal[1], high = pal[2], ...) - } #' Binned color scale constructor for Norad colors #' -#' @param palette Character name of palette in norad_palettes +#' @param palette Character name of palette in norad_palettes. One of "greens", "browns", or "purples" #' @param direction Integer indicating whether the palette should be reversed #' @param breaks How to break down continuous data into bins. Computed automatically by default. #' @param ... Additional arguments passed to ggplot2::scale_color_steps() @@ -224,11 +211,8 @@ scale_fill_norad_binned <- function(palette = "greens", direction = 1, breaks = #' scale_color_norad_binned <- function(palette = "greens", direction = 1, breaks = waiver(), ...) { - pal <- norad_pal(palette) - ggplot2::scale_color_steps(low = pal[1], high = pal[2], ...) - } #' @examples diff --git a/man/ggnorad.Rd b/man/ggnorad.Rd index e8dcbd2..7ba80f5 100644 --- a/man/ggnorad.Rd +++ b/man/ggnorad.Rd @@ -2,13 +2,18 @@ % Please edit documentation in R/ggnorad.R \name{ggnorad} \alias{ggnorad} -\title{Wrapper function to load norad theme} +\title{Wrapper function to load Norad theme for ggplot2. +Also sets Norad's discrete and continuous color palettes as the default for the session.} \usage{ -ggnorad(style = "default") +ggnorad(style = "default", norad_colors = TRUE) } \arguments{ -\item{style}{Plot style. One of "default", "biglight1", "biglight2", "bigdark".} +\item{style}{Plot style. One of "default", "biglight1", "biglight2", "bigdark", +"maplight", "mapdark", or "light"} + +\item{norad_colors}{Logical. Should Norad's color palettes be set as the default for the session? Default is TRUE.} } \description{ -Wrapper function to load norad theme +Wrapper function to load Norad theme for ggplot2. +Also sets Norad's discrete and continuous color palettes as the default for the session. } diff --git a/man/palette_gen_c.Rd b/man/palette_gen_c.Rd index 2a19bb2..588cf4f 100644 --- a/man/palette_gen_c.Rd +++ b/man/palette_gen_c.Rd @@ -4,7 +4,7 @@ \alias{palette_gen_c} \title{Helper function for continuous color scales} \usage{ -palette_gen_c(palette = "main", direction = 1, ...) +palette_gen_c(palette = "greens", direction = 1, ...) } \arguments{ \item{palette}{Character name of palette in norad_palettes} diff --git a/man/scale_color_norad_binned.Rd b/man/scale_color_norad_binned.Rd index 0bfac2f..cb1d1d0 100644 --- a/man/scale_color_norad_binned.Rd +++ b/man/scale_color_norad_binned.Rd @@ -12,7 +12,7 @@ scale_color_norad_binned( ) } \arguments{ -\item{palette}{Character name of palette in norad_palettes} +\item{palette}{Character name of palette in norad_palettes. One of "greens", "browns", or "purples"} \item{direction}{Integer indicating whether the palette should be reversed} diff --git a/man/scale_color_norad_c.Rd b/man/scale_color_norad_c.Rd index 653342b..f9cf269 100644 --- a/man/scale_color_norad_c.Rd +++ b/man/scale_color_norad_c.Rd @@ -7,7 +7,7 @@ scale_color_norad_c(palette = "greens", direction = 1, ...) } \arguments{ -\item{palette}{Character name of palette in norad_palettes} +\item{palette}{Character name of palette in norad_palettes. One of "greens", "browns", or "purples"} \item{direction}{Integer indicating whether the palette should be reversed} diff --git a/man/scale_fill_norad_binned.Rd b/man/scale_fill_norad_binned.Rd index f3c3f29..c8020e5 100644 --- a/man/scale_fill_norad_binned.Rd +++ b/man/scale_fill_norad_binned.Rd @@ -12,7 +12,7 @@ scale_fill_norad_binned( ) } \arguments{ -\item{palette}{Character name of palette in norad_palettes} +\item{palette}{Character name of palette in norad_palettes. One of "greens", "browns", or "purples"} \item{direction}{Integer indicating whether the palette should be reversed} diff --git a/man/scale_fill_norad_c.Rd b/man/scale_fill_norad_c.Rd index 9a74bf3..ba416d4 100644 --- a/man/scale_fill_norad_c.Rd +++ b/man/scale_fill_norad_c.Rd @@ -7,7 +7,7 @@ scale_fill_norad_c(palette = "greens", direction = 1, ...) } \arguments{ -\item{palette}{Character name of palette in norad_palettes} +\item{palette}{Character name of palette in norad_palettes. One of "greens", "browns", or "purples"} \item{direction}{Integer indicating whether the palette should be reversed} From 49568828078b4e896e646b3e25972ee0fb24b035 Mon Sep 17 00:00:00 2001 From: Eivind Moe Hammersmark Date: Thu, 23 May 2024 09:03:31 +0200 Subject: [PATCH 2/3] fix binned colors --- R/ggnorad.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/ggnorad.R b/R/ggnorad.R index deb47c3..e4ae4b1 100644 --- a/R/ggnorad.R +++ b/R/ggnorad.R @@ -60,5 +60,7 @@ ggnorad <- function(style = "default", norad_colors = TRUE) { options(ggplot2.discrete.fill = scale_fill_norad) options(ggplot2.continuous.colour = scale_color_norad_c) options(ggplot2.continuous.fill = scale_fill_norad_c) + options(ggplot2.binned.fill = scale_fill_norad_binned) + options(ggplot2.binned.colour = scale_color_norad_binned) } } From 3397a1c0afeb1d6fb9ae1fed6ef577b3f5b7d2e7 Mon Sep 17 00:00:00 2001 From: Eivind Moe Hammersmark Date: Tue, 28 May 2024 13:00:15 +0200 Subject: [PATCH 3/3] fix scale_name error. Add vignettes --- Meta/vignette.rds | Bin 0 -> 221 bytes R/palette_functions.R | 2 + doc/noradplot-no-subtitle.R | 50 + doc/noradplot-no-subtitle.Rmd | 79 ++ doc/noradplot-no-subtitle.html | 1869 +++++++++++++++++++++++++++++++ doc/noradplot.R | 54 + doc/noradplot.Rmd | 83 ++ doc/noradplot.html | 1931 ++++++++++++++++++++++++++++++++ 8 files changed, 4068 insertions(+) create mode 100644 Meta/vignette.rds create mode 100644 doc/noradplot-no-subtitle.R create mode 100644 doc/noradplot-no-subtitle.Rmd create mode 100644 doc/noradplot-no-subtitle.html create mode 100644 doc/noradplot.R create mode 100644 doc/noradplot.Rmd create mode 100644 doc/noradplot.html diff --git a/Meta/vignette.rds b/Meta/vignette.rds new file mode 100644 index 0000000000000000000000000000000000000000..f067b0f0017782fb20e80eb9be47b128b9473377 GIT binary patch literal 221 zcmV<303!b%iwFP!0000019eWz4uUWcEP^N)j0p#${{UY>xOg$fgV!oGk`zjyhIsSK z!3DMmJ`UaP%+Bu2$tHwMh+#n0q19a|CcIV06AS)LDsmcSTu3h!UU5ImSaRkck_ZJ( zFKEf}w$%^6iLr9~+vg?|j*8{msAb3d>pwYhycnbe=(d~P1v2>m@J7RFcxsx`gcUe6 zku<`XGbK1S)(G@{5MryTFtdPVER70;^BsGXA_qJ+vT{-S%FJn!J)zWfU416Ha9XHD XinJptsejF3A5irIP@Xc8?EwG))g59k literal 0 HcmV?d00001 diff --git a/R/palette_functions.R b/R/palette_functions.R index 314a253..43bd43d 100644 --- a/R/palette_functions.R +++ b/R/palette_functions.R @@ -133,6 +133,7 @@ palette_gen_c <- function(palette = "greens", direction = 1, ...) { scale_color_norad <- function(palette = "main", direction = 1, ...) { ggplot2::discrete_scale( aesthetics = "color", + scale_name = "norad", # Deprecated in 3.5.0, but required for version <= 3.5.0, so keep for now palette = palette_gen(palette, direction), ... ) @@ -150,6 +151,7 @@ scale_color_norad <- function(palette = "main", direction = 1, ...) { scale_fill_norad <- function(palette = "main", direction = 1, ...) { ggplot2::discrete_scale( aesthetics = "fill", + scale_name = "norad", # Deprecated in 3.5.0, but required for version <= 3.5.0, so keep for now palette = palette_gen(palette, direction), ... ) diff --git a/doc/noradplot-no-subtitle.R b/doc/noradplot-no-subtitle.R new file mode 100644 index 0000000..562a7be --- /dev/null +++ b/doc/noradplot-no-subtitle.R @@ -0,0 +1,50 @@ +## ----include = FALSE---------------------------------------------------------- +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + dev = "svglite" +) + +## ----setup-------------------------------------------------------------------- +library(ggplot2) +library(noradplot) + +ggnorad("default") + + +## ----------------------------------------------------------------------------- +ggnorad("default") + +ggplot(mpg, aes(displ, hwy, color = class)) + + geom_point() + + scale_color_norad() + + labs(title = "Displacement and highway mileage", + caption = "Source: mpg dataset from ggplot2 package") + +## ----------------------------------------------------------------------------- +ggplot(mpg, aes(class)) + + geom_bar() + + scale_y_continuous(expand = expansion(mult = c(0, 0.05))) + + labs(title = "Number of vehicles", + caption = "Source: mpg dataset from ggplot2 package") + +## ----message=FALSE------------------------------------------------------------ +library(dplyr) + +df <- tibble("temp" = as.numeric(nhtemp), "time" = as.numeric(time(nhtemp))) + +df |> + ggplot(aes(time, temp)) + + geom_line() + + scale_color_norad() + + labs(title = "New Haven temperature", + caption = "Source: nhtemp dataset from datasets package") + +## ----------------------------------------------------------------------------- +ggplot(mpg, aes(displ, hwy, color = class)) + + geom_point() + + scale_color_norad() + + labs(title = "Displacement and highway mileage", + caption = "Source: mpg dataset from ggplot2 package") + + facet_wrap(~class) + diff --git a/doc/noradplot-no-subtitle.Rmd b/doc/noradplot-no-subtitle.Rmd new file mode 100644 index 0000000..5a76bdf --- /dev/null +++ b/doc/noradplot-no-subtitle.Rmd @@ -0,0 +1,79 @@ +--- +title: "noradplot" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{noradplot} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + dev = "svglite" +) +``` + +```{r setup} +library(ggplot2) +library(noradplot) + +ggnorad("default") + +``` + +## Scatter plot +```{r} +#| fig.width: 6 +#| fig.height: 4 +ggnorad("default") + +ggplot(mpg, aes(displ, hwy, color = class)) + + geom_point() + + scale_color_norad() + + labs(title = "Displacement and highway mileage", + caption = "Source: mpg dataset from ggplot2 package") +``` + +## Bar chart +```{r} +#| fig.width: 6 +#| fig.height: 4 + +ggplot(mpg, aes(class)) + + geom_bar() + + scale_y_continuous(expand = expansion(mult = c(0, 0.05))) + + labs(title = "Number of vehicles", + caption = "Source: mpg dataset from ggplot2 package") +``` + +## Line chart +```{r, message=FALSE} +#| fig.width: 6 +#| fig.height: 4 + +library(dplyr) + +df <- tibble("temp" = as.numeric(nhtemp), "time" = as.numeric(time(nhtemp))) + +df |> + ggplot(aes(time, temp)) + + geom_line() + + scale_color_norad() + + labs(title = "New Haven temperature", + caption = "Source: nhtemp dataset from datasets package") +``` + +## Faceted plot +```{r} +#| fig.width: 6 +#| fig.height: 5 + +ggplot(mpg, aes(displ, hwy, color = class)) + + geom_point() + + scale_color_norad() + + labs(title = "Displacement and highway mileage", + caption = "Source: mpg dataset from ggplot2 package") + + facet_wrap(~class) +``` diff --git a/doc/noradplot-no-subtitle.html b/doc/noradplot-no-subtitle.html new file mode 100644 index 0000000..a45d3c8 --- /dev/null +++ b/doc/noradplot-no-subtitle.html @@ -0,0 +1,1869 @@ + + + + + + + + + + + + + + +noradplot + + + + + + + + + + + + + + + + + + + + + + + + + + +

noradplot

+ + + +
library(ggplot2)
+library(noradplot)
+
+ggnorad("default")
+
+

Scatter plot

+
ggnorad("default")
+
+ggplot(mpg, aes(displ, hwy, color = class)) + 
+  geom_point() +
+  scale_color_norad() +
+  labs(title = "Displacement and highway mileage",
+       caption = "Source: mpg dataset from ggplot2 package")
+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+
+
+

Bar chart

+
ggplot(mpg, aes(class)) + 
+  geom_bar() +
+  scale_y_continuous(expand = expansion(mult = c(0, 0.05))) +
+  labs(title = "Number of vehicles",
+       caption = "Source: mpg dataset from ggplot2 package")
+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+
+
+

Line chart

+
library(dplyr)
+
+df <- tibble("temp" = as.numeric(nhtemp), "time" = as.numeric(time(nhtemp))) 
+
+df |> 
+  ggplot(aes(time, temp)) + 
+  geom_line() +
+  scale_color_norad() +
+  labs(title = "New Haven temperature",
+       caption = "Source: nhtemp dataset from datasets package")
+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+
+
+

Faceted plot

+
ggplot(mpg, aes(displ, hwy, color = class)) + 
+  geom_point() +
+  scale_color_norad() +
+  labs(title = "Displacement and highway mileage",
+       caption = "Source: mpg dataset from ggplot2 package") +
+  facet_wrap(~class)
+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+
+ + + + + + + + + + + diff --git a/doc/noradplot.R b/doc/noradplot.R new file mode 100644 index 0000000..9b9da8e --- /dev/null +++ b/doc/noradplot.R @@ -0,0 +1,54 @@ +## ----include = FALSE---------------------------------------------------------- +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + dev = "svglite" +) + +## ----setup-------------------------------------------------------------------- +library(ggplot2) +library(noradplot) + +ggnorad("default") + + +## ----------------------------------------------------------------------------- +ggnorad("default") + +ggplot(mpg, aes(displ, hwy, color = class)) + + geom_point() + + scale_color_norad() + + labs(title = "Displacement and highway mileage", + subtitle = "By vehicle class", + caption = "Source: mpg dataset from ggplot2 package") + +## ----------------------------------------------------------------------------- +ggplot(mpg, aes(class)) + + geom_bar() + + scale_y_continuous(expand = expansion(mult = c(0, 0.05))) + + labs(title = "Number of vehicles", + subtitle = "By vehicle class", + caption = "Source: mpg dataset from ggplot2 package") + +## ----message=FALSE------------------------------------------------------------ +library(dplyr) + +df <- tibble("temp" = as.numeric(nhtemp), "time" = as.numeric(time(nhtemp))) + +df |> + ggplot(aes(time, temp)) + + geom_line() + + scale_color_norad() + + labs(title = "New Haven temperature", + subtitle = "Data for 1912-1971", + caption = "Source: nhtemp dataset from datasets package") + +## ----------------------------------------------------------------------------- +ggplot(mpg, aes(displ, hwy, color = class)) + + geom_point() + + scale_color_norad() + + labs(title = "Displacement and highway mileage", + subtitle = "By vehicle class", + caption = "Source: mpg dataset from ggplot2 package") + + facet_wrap(~class) + diff --git a/doc/noradplot.Rmd b/doc/noradplot.Rmd new file mode 100644 index 0000000..ac77f48 --- /dev/null +++ b/doc/noradplot.Rmd @@ -0,0 +1,83 @@ +--- +title: "noradplot" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{noradplot} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + dev = "svglite" +) +``` + +```{r setup} +library(ggplot2) +library(noradplot) + +ggnorad("default") + +``` + +## Scatter plot +```{r} +#| fig.width: 6 +#| fig.height: 4 +ggnorad("default") + +ggplot(mpg, aes(displ, hwy, color = class)) + + geom_point() + + scale_color_norad() + + labs(title = "Displacement and highway mileage", + subtitle = "By vehicle class", + caption = "Source: mpg dataset from ggplot2 package") +``` + +## Bar chart +```{r} +#| fig.width: 6 +#| fig.height: 4 + +ggplot(mpg, aes(class)) + + geom_bar() + + scale_y_continuous(expand = expansion(mult = c(0, 0.05))) + + labs(title = "Number of vehicles", + subtitle = "By vehicle class", + caption = "Source: mpg dataset from ggplot2 package") +``` + +## Line chart +```{r, message=FALSE} +#| fig.width: 6 +#| fig.height: 4 + +library(dplyr) + +df <- tibble("temp" = as.numeric(nhtemp), "time" = as.numeric(time(nhtemp))) + +df |> + ggplot(aes(time, temp)) + + geom_line() + + scale_color_norad() + + labs(title = "New Haven temperature", + subtitle = "Data for 1912-1971", + caption = "Source: nhtemp dataset from datasets package") +``` + +## Faceted plot +```{r} +#| fig.width: 6 +#| fig.height: 5 + +ggplot(mpg, aes(displ, hwy, color = class)) + + geom_point() + + scale_color_norad() + + labs(title = "Displacement and highway mileage", + subtitle = "By vehicle class", + caption = "Source: mpg dataset from ggplot2 package") + + facet_wrap(~class) +``` diff --git a/doc/noradplot.html b/doc/noradplot.html new file mode 100644 index 0000000..51ffb46 --- /dev/null +++ b/doc/noradplot.html @@ -0,0 +1,1931 @@ + + + + + + + + + + + + + + +noradplot + + + + + + + + + + + + + + + + + + + + + + + + + + +

noradplot

+ + + +
library(ggplot2)
+library(noradplot)
+
+ggnorad("default")
+
+

Scatter plot

+
ggnorad("default")
+
+ggplot(mpg, aes(displ, hwy, color = class)) + 
+  geom_point() +
+  scale_color_norad() +
+  labs(title = "Displacement and highway mileage",
+       subtitle = "By vehicle class",
+       caption = "Source: mpg dataset from ggplot2 package")
+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+
+
+

Bar chart

+
ggplot(mpg, aes(class)) + 
+  geom_bar() +
+  scale_y_continuous(expand = expansion(mult = c(0, 0.05))) +
+  labs(title = "Number of vehicles",
+       subtitle = "By vehicle class",
+       caption = "Source: mpg dataset from ggplot2 package")
+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+
+
+

Line chart

+
library(dplyr)
+
+df <- tibble("temp" = as.numeric(nhtemp), "time" = as.numeric(time(nhtemp))) 
+
+df |> 
+  ggplot(aes(time, temp)) + 
+  geom_line() +
+  scale_color_norad() +
+  labs(title = "New Haven temperature",
+       subtitle = "Data for 1912-1971",
+       caption = "Source: nhtemp dataset from datasets package")
+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+
+
+

Faceted plot

+
ggplot(mpg, aes(displ, hwy, color = class)) + 
+  geom_point() +
+  scale_color_norad() +
+  labs(title = "Displacement and highway mileage",
+       subtitle = "By vehicle class",
+       caption = "Source: mpg dataset from ggplot2 package") +
+  facet_wrap(~class)
+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+
+ + + + + + + + + + +