diff --git a/DESCRIPTION b/DESCRIPTION index 7d064e3..b17564f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: ggpattern Type: Package Title: 'ggplot2' Pattern Geoms -Version: 1.3.2-3 +Version: 1.3.2-4 Authors@R: c(person("Mike", "FC", role = "aut"), person("Trevor L.", "Davis", role = c("aut", "cre"), email = "trevor.l.davis@gmail.com", diff --git a/README.Rmd b/README.Rmd index e09241e..a3c4fee 100644 --- a/README.Rmd +++ b/README.Rmd @@ -250,7 +250,6 @@ See the vignette on developing patterns: [`vignette("developing-patterns", packa #### Other examples * [Animating Patterns with `{gganimate}`](https://trevorldavis.com/R/ggpattern/dev/articles/gganimate.html): `vignette("gganimate", package = "ggpattern")` -* [Creating the Logo in R](https://trevorldavis.com/R/ggpattern/dev/articles/create-logo.html): `vignette("create-logo", package = "ggpattern")` # Limitations diff --git a/README.md b/README.md index b6151c0..20f46c1 100644 --- a/README.md +++ b/README.md @@ -217,7 +217,6 @@ See the vignette on developing patterns: [`vignette("developing-patterns", packa #### Other examples * [Animating Patterns with `{gganimate}`](https://trevorldavis.com/R/ggpattern/dev/articles/gganimate.html): `vignette("gganimate", package = "ggpattern")` -* [Creating the Logo in R](https://trevorldavis.com/R/ggpattern/dev/articles/create-logo.html): `vignette("create-logo", package = "ggpattern")` # Limitations diff --git a/data-raw/logo.R b/data-raw/logo.R new file mode 100644 index 0000000..02e95a8 --- /dev/null +++ b/data-raw/logo.R @@ -0,0 +1,66 @@ +library("grid") +library("ggplot2") +library("ggpattern") +library("piecepackr") + +draw_logo <- function(bleed = FALSE, cut = FALSE) { + angle <- seq(0, 2 * pi, length.out = 7) + pi / 6 + polygon_df <- data.frame( + angle = angle, + x = cos(angle), + y = sin(angle) + ) + p <- ggplot(polygon_df) + + geom_polygon_pattern( + aes(x = x, y = y), + fill = "white", + colour = "black", + pattern_spacing = 0.15, + pattern_density = 0.4, + pattern_fill = "lightblue", + pattern_colour = "#002366", + pattern_angle = 45 + ) + + labs(title = "ggpattern") + + coord_equal() + + theme_bw(25) + + theme(axis.title = element_blank()) + + plot_grob <- ggplotGrob(p) + + w <- 4.5 + grid.newpage() + pushViewport(viewport(width = unit(w, "inches"), height = unit(w, "inches"))) + hex <- pp_shape("convex6") + + # Draw hex background + grid.draw(hex$shape(gp = gpar(fill = "white", col = "black", lwd = 4))) + + # Draw ggplot grob clipped to the hex shape via a mask + hex_mask <- as.mask(hex$shape(gp = gpar(fill = "white", col = NA))) + pushViewport(viewport(mask = hex_mask)) + pushViewport(viewport(x = 0.45, height = unit(0.8 * w, "inches"))) + grid.draw(plot_grob) + popViewport() + popViewport() + + # Redraw hex border on top to clean up edges + grid.draw(hex$shape(gp = gpar(fill = NA, col = "black", lwd = 4))) + + if (isTRUE(bleed) && isTRUE(cut)) { + pushViewport(viewport(width = unit(5 / 6, "npc"), height = unit(5 / 6, "npc"))) + grid.draw(hex$shape(gp = gpar(fill = "transparent", col = "orange"))) + popViewport() + } + + popViewport() +} + +w <- 4.5 +svg("man/figures/logo.svg", width = w, height = w, bg = "transparent") +draw_logo() +dev.off() + +png("man/figures/logo.png", width = w, height = w, units = "in", res = 72, bg = "transparent") +draw_logo() +dev.off() diff --git a/man/figures/logo.png b/man/figures/logo.png index dd213c2..b6c2157 100644 Binary files a/man/figures/logo.png and b/man/figures/logo.png differ diff --git a/vignettes/create-logo.Rmd b/vignettes/create-logo.Rmd deleted file mode 100644 index f1d82f6..0000000 --- a/vignettes/create-logo.Rmd +++ /dev/null @@ -1,67 +0,0 @@ ---- -title: "Creating the Logo in R" -output: rmarkdown::html_vignette -vignette: > - %\VignetteIndexEntry{Creating the Logo in R} - %\VignetteEngine{knitr::rmarkdown} - %\VignetteEncoding{UTF-8} ---- - -```{r, include = FALSE} -knitr::opts_chunk$set( - collapse = TRUE, - comment = "#>", - fig.width = 6, - fig.height = 6 -) -``` - -```{r setup} -suppressPackageStartupMessages({ - library(ggplot2) - library(ggpattern) -}) -``` - -Creating the hex logo for `ggpattern` ------------------------------------------------------------------------------- - -```{r logo, fig.alt="The ggpattern logo: a ggplot2 plot of a striped hexagon."} -#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Data frame for a polygon -#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -angle <- seq(0, 2*pi, length.out = 7) + pi/6 -polygon_df <- data.frame( - angle = angle, - x = cos(angle), - y = sin(angle) -) - -#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Create a plot of a patterned polygon -#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -p <- ggplot(polygon_df) + - geom_polygon_pattern( - aes(x = x, y = y), - fill = 'white', - colour = 'black', - pattern_spacing = 0.15, - pattern_density = 0.4, - pattern_fill = 'lightblue', - pattern_colour = '#002366', - pattern_angle = 45 - ) + - labs(title = "ggpattern") + - coord_equal() + - theme_bw(25) + - theme(axis.title = element_blank()) - -p -``` - -```{r echo = FALSE, eval = FALSE} -filename <- here::here("man", "figures", "logo.png") -png(filename) -print(p) -invisible(dev.off()) -```