├── .gitignore ├── LICENSE ├── .Rbuildignore ├── man ├── figures │ ├── README-example-1.png │ ├── README-example-rings-1.png │ └── README-example-no-circle-1.png ├── pipe.Rd ├── contour_plot.Rd ├── contour_shape.Rd └── contour_grid.Rd ├── NAMESPACE ├── R ├── utils-pipe.R ├── contour_grid.R ├── contour_shape.R ├── helpers.R └── contour_plot.R ├── contouR.Rproj ├── DESCRIPTION ├── LICENSE.md ├── README.md └── README.Rmd /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2021 2 | COPYRIGHT HOLDER: Ijeamaka Anyene 3 | -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^contouR\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^LICENSE\.md$ 4 | ^README\.Rmd$ 5 | -------------------------------------------------------------------------------- /man/figures/README-example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ijeamakaanyene/contouR/HEAD/man/figures/README-example-1.png -------------------------------------------------------------------------------- /man/figures/README-example-rings-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ijeamakaanyene/contouR/HEAD/man/figures/README-example-rings-1.png -------------------------------------------------------------------------------- /man/figures/README-example-no-circle-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ijeamakaanyene/contouR/HEAD/man/figures/README-example-no-circle-1.png -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export("%>%") 4 | export(contour_grid) 5 | export(contour_plot) 6 | export(contour_shape) 7 | importFrom(magrittr,"%>%") 8 | importFrom(rlang,.data) 9 | -------------------------------------------------------------------------------- /R/utils-pipe.R: -------------------------------------------------------------------------------- 1 | #' Pipe operator 2 | #' 3 | #' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. 4 | #' 5 | #' @name %>% 6 | #' @rdname pipe 7 | #' @keywords internal 8 | #' @export 9 | #' @importFrom magrittr %>% 10 | #' @usage lhs \%>\% rhs 11 | NULL 12 | -------------------------------------------------------------------------------- /man/pipe.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils-pipe.R 3 | \name{\%>\%} 4 | \alias{\%>\%} 5 | \title{Pipe operator} 6 | \usage{ 7 | lhs \%>\% rhs 8 | } 9 | \description{ 10 | See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /contouR.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: No 4 | SaveWorkspace: No 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | LineEndingConversion: Posix 18 | 19 | BuildType: Package 20 | PackageUseDevtools: Yes 21 | PackageInstallArgs: --no-multiarch --with-keep.source 22 | PackageRoxygenize: rd,collate,namespace 23 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: contouR 2 | Title: Generate images using the idea of contours 3 | Version: 0.0.0.9000 4 | Authors@R: 5 | person(given = "Ijeamaka", 6 | family = "Anyene", 7 | role = c("aut", "cre"), 8 | email = "Ijeamaka.Anyene@gmail.com", 9 | comment = c(ORCID = "YOUR-ORCID-ID")) 10 | Description: A generative system for creating interesting patterns using a grid system and ggplot2::geom_contour(). 11 | License: MIT + file LICENSE 12 | Encoding: UTF-8 13 | LazyData: true 14 | Roxygen: list(markdown = TRUE) 15 | RoxygenNote: 7.1.1 16 | Imports: 17 | magrittr, 18 | dplyr, 19 | ggplot2, 20 | rlang 21 | -------------------------------------------------------------------------------- /man/contour_plot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/contour_plot.R 3 | \name{contour_plot} 4 | \alias{contour_plot} 5 | \title{Plot the contour grid} 6 | \usage{ 7 | contour_plot( 8 | grid_shape, 9 | rings = NA, 10 | background_col = "#2a3c4b", 11 | line_col = "#e9ebed" 12 | ) 13 | } 14 | \arguments{ 15 | \item{grid_shape}{a dataframe of x, y, and z points} 16 | 17 | \item{rings}{a dataframe of x, y, and group points} 18 | 19 | \item{background_col}{a character string used for the background color of the plot} 20 | 21 | \item{line_col}{a character string used for the line colors of your plot} 22 | } 23 | \value{ 24 | a ggplot2 object with some default parameters of line size of 0.25, 25 | linejoin is round, and uses theme_void() to remove extra elements 26 | } 27 | \description{ 28 | Plot the contour grid 29 | } 30 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2021 Ijeamaka Anyene 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /man/contour_shape.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/contour_shape.R 3 | \name{contour_shape} 4 | \alias{contour_shape} 5 | \title{Turn the contour grid into a shape} 6 | \usage{ 7 | contour_shape( 8 | grid, 9 | radius, 10 | x_center, 11 | y_center, 12 | ring_system = "none", 13 | num_rings = 0 14 | ) 15 | } 16 | \arguments{ 17 | \item{grid}{dataframe of x, y, and z points} 18 | 19 | \item{radius}{radius of the shape} 20 | 21 | \item{x_center}{x coordinate of the center of the shape} 22 | 23 | \item{y_center}{y coordinate of the center of the shape} 24 | 25 | \item{ring_system}{ring system options: halo or multiple. 26 | This is optional, if you do not want rings leave as default} 27 | 28 | \item{num_rings}{The number of rings around the contour shape, 29 | if choosing multiple ring systems. 30 | This is optional, if you do not want rings leave default as null} 31 | } 32 | \value{ 33 | a list where the first item is a data frame with the 34 | x, y and z coordinates of the points and the second items is a 35 | data frame of the coordinates for the rings (if ring system selected) 36 | } 37 | \description{ 38 | Turn the contour grid into a shape 39 | } 40 | -------------------------------------------------------------------------------- /man/contour_grid.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/contour_grid.R 3 | \name{contour_grid} 4 | \alias{contour_grid} 5 | \title{Create the contour grid} 6 | \usage{ 7 | contour_grid(seed = 117, grid_size, point_dist, z_method, z, z_span) 8 | } 9 | \arguments{ 10 | \item{seed}{Value or seed for the random number generator (numeric)} 11 | 12 | \item{grid_size}{Maximum value for x and y (numeric)} 13 | 14 | \item{point_dist}{Increment of the sequence for x and y (numeric)} 15 | 16 | \item{z_method}{Distribution options for random generation for z values; options are rnorm, rpois, runif} 17 | 18 | \item{z}{Values for creating the z values (numeric)} 19 | 20 | \item{z_span}{Range of values for z (numeric), used as the additional parameter for the random number distribution} 21 | } 22 | \value{ 23 | data frame with the x, y and z coordinates of the points 24 | } 25 | \description{ 26 | Create the contour grid 27 | } 28 | \examples{ 29 | # generates a 20 by 20 grid of points, with a distance of .25 between points, 30 | # and the z values are generated using a normal distribution with a mean of 3 and SD of 1 31 | grid_points = contour_grid(grid_size = 20, point_dist = .25, z_method = "rnorm", z = 3, z_span = 1) 32 | 33 | } 34 | -------------------------------------------------------------------------------- /R/contour_grid.R: -------------------------------------------------------------------------------- 1 | #' Create the contour grid 2 | #' 3 | #' @param seed Value or seed for the random number generator (numeric) 4 | #' @param grid_size Maximum value for x and y (numeric) 5 | #' @param point_dist Increment of the sequence for x and y (numeric) 6 | #' @param z_method Distribution options for random generation for z values; options are rnorm, rpois, runif 7 | #' @param z Values for creating the z values (numeric) 8 | #' @param z_span Range of values for z (numeric), used as the additional parameter for the random number distribution 9 | #' 10 | #' @return data frame with the x, y and z coordinates of the points 11 | #' @export 12 | #' 13 | #' @examples 14 | #' # generates a 20 by 20 grid of points, with a distance of .25 between points, 15 | #' # and the z values are generated using a normal distribution with a mean of 3 and SD of 1 16 | #' grid_points = contour_grid(grid_size = 20, point_dist = .25, z_method = "rnorm", z = 3, z_span = 1) 17 | #' 18 | #' @importFrom rlang .data 19 | contour_grid = function(seed = 117, 20 | grid_size, 21 | point_dist, 22 | z_method, 23 | z, 24 | z_span){ 25 | 26 | if(!is.numeric(grid_size)){stop("grid_size must be a numeric value")} 27 | if(!is.numeric(point_dist)){stop("point_dist must be a numeric value")} 28 | if(!is.numeric(z)){stop("z must be a numeric value")} 29 | if(!is.numeric(z_span)){stop("z_span must be a numeric value")} 30 | if(z_method == "rpois" & z < 0){stop("rpois method requires a z greater than zero")} 31 | if(!(z_method %in% c("rpois", "rnorm", "runif", "sample"))){stop("z_method must be selected from allowed distributions: rpois, rnorm, and runif, or sample")} 32 | 33 | 34 | # parameters defining contour grid 35 | param = list( 36 | seed = seed, 37 | grid_size = grid_size, 38 | point_dist = point_dist, 39 | z_method = z_method, 40 | z = z, 41 | z_span = z_span) 42 | 43 | # setting seed 44 | set.seed(param$seed) 45 | 46 | # Creating output grid 47 | grid_points = initiate_grid(param) %>% 48 | calculate_z(param) 49 | 50 | return(grid_points) 51 | } 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /R/contour_shape.R: -------------------------------------------------------------------------------- 1 | #' Turn the contour grid into a shape 2 | #' 3 | #' @param grid dataframe of x, y, and z points 4 | #' @param radius radius of the shape 5 | #' @param x_center x coordinate of the center of the shape 6 | #' @param y_center y coordinate of the center of the shape 7 | #' @param ring_system ring system options: halo or multiple. 8 | #' This is optional, if you do not want rings leave as default 9 | #' @param num_rings The number of rings around the contour shape, 10 | #' if choosing multiple ring systems. 11 | #' This is optional, if you do not want rings leave default as null 12 | #' 13 | #' @return a list where the first item is a data frame with the 14 | #' x, y and z coordinates of the points and the second items is a 15 | #' data frame of the coordinates for the rings (if ring system selected) 16 | #' @export 17 | #' 18 | #' @importFrom rlang .data 19 | contour_shape = function(grid, 20 | radius, 21 | x_center, 22 | y_center, 23 | ring_system = "none", 24 | num_rings = 0){ 25 | 26 | if(!is.data.frame(grid)){stop("grid must be a dataframe")} 27 | if(!is.numeric(radius)){stop("radius must be numeric")} 28 | if(!is.numeric(x_center)){stop("x_center must be numeric")} 29 | if(!is.numeric(y_center)){stop("y_center must be numeric")} 30 | if(!(ring_system %in% c("multiple", "halo", "none"))){ 31 | stop("ring system must be selected from options: multiple, halo, or none") 32 | } 33 | 34 | # params needed in functions 35 | param = list( 36 | x_center = x_center, 37 | y_center = y_center, 38 | radius = radius, 39 | num_rings = num_rings) 40 | 41 | # turn input grid into a circle 42 | grid_shape = grid %>% 43 | create_shape(param) 44 | 45 | # add optional rings 46 | if(ring_system == "multiple"){ 47 | rings = create_multiple_rings(param) 48 | 49 | return(list(grid_shape = grid_shape, rings = rings)) 50 | 51 | } else if(ring_system == "halo"){ 52 | rings = create_halo(param) 53 | 54 | return(list(grid_shape = grid_shape, rings = rings)) 55 | } 56 | 57 | 58 | 59 | return(list(grid_shape = grid_shape)) 60 | } 61 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | # contouR 5 | 6 | 7 | 8 | 9 | 10 | contouR is a package that is a wraparound for `ggplot2::geom_contour()` 11 | to use for generative art. `geom_contour()` allows one to visualize 3D 12 | surfaces in 2D by using x, y and z coordinates. To change it up from the 13 | typical contour plot, there are three different distributions used to 14 | generate the z values: `rnorm()`, `runif()`, and `rpois()`. 15 | 16 | ## Installation 17 | 18 | You can install the current verion of contouR from 19 | [GitHub](https://github.com/) with: 20 | 21 | ``` r 22 | # install.packages("devtools") 23 | devtools::install_github("Ijeamakaanyene/contouR") 24 | ``` 25 | 26 | If you make any fun art with this package, please feel free to contact 27 | me on twitter @ijeamaka\_a 28 | to show it off 🌔 29 | 30 | ## Example: without rings 31 | 32 | ``` r 33 | library(contouR) 34 | 35 | #set up your data 36 | setup = contour_grid(grid_size = 30, point_dist = .25, 37 | z_method = "runif", z = 1, z_span = 3) %>% 38 | contour_shape(radius = 10.2, 39 | x_center = 7, y_center = 7) 40 | 41 | # plot your data 42 | contour_plot(setup$grid_shape) + 43 | ggplot2::xlim(1, 30) + 44 | ggplot2::ylim(1, 30) 45 | ``` 46 | 47 | 48 | 49 | ## Example: with rings 50 | 51 | ``` r 52 | #set up your data 53 | setup = contour_grid(grid_size = 30, point_dist = .25, 54 | z_method = "runif", z = 1, z_span = 3) %>% 55 | contour_shape(radius = 10.2, 56 | x_center = 10, y_center = 10, 57 | ring_system = "multiple", 58 | num_rings = 10) 59 | 60 | # plot your data 61 | contour_plot(setup$grid_shape, setup$rings) + 62 | ggplot2::xlim(1, 30) + 63 | ggplot2::ylim(1, 30) 64 | #> Warning: Removed 407 row(s) containing missing values (geom_path). 65 | ``` 66 | 67 | 68 | 69 | ## Example: without contour shape 70 | 71 | ``` r 72 | #set up your data 73 | setup = contour_grid(grid_size = 30, point_dist = .25, 74 | z_method = "runif", z = 1, z_span = 3) 75 | 76 | # plot your data 77 | contour_plot(setup) + 78 | ggplot2::xlim(1, 30) + 79 | ggplot2::ylim(1, 30) 80 | ``` 81 | 82 | 83 | -------------------------------------------------------------------------------- /README.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: github_document 3 | --- 4 | 5 | 6 | 7 | ```{r, include = FALSE} 8 | knitr::opts_chunk$set( 9 | collapse = TRUE, 10 | comment = "#>", 11 | fig.path = "man/figures/README-", 12 | out.width = "100%" 13 | ) 14 | ``` 15 | 16 | # contouR 17 | 18 | 19 | 20 | 21 | contouR is a package that is a wraparound for `ggplot2::geom_contour()` to use for generative art. `geom_contour()` allows one to visualize 3D surfaces in 2D by using x, y and z coordinates. To change it up from the typical contour plot, there are three different distributions used to generate the z values: `rnorm()`, `runif()`, and `rpois()`. 22 | 23 | ## Installation 24 | 25 | You can install the current verion of contouR from [GitHub](https://github.com/) with: 26 | 27 | ``` r 28 | # install.packages("devtools") 29 | devtools::install_github("Ijeamakaanyene/contouR") 30 | ``` 31 | 32 | If you make any fun art with this package, please feel free to contact me on twitter @ijeamaka_a to show it off `r emo::ji("moon")` 33 | 34 | ## Example: without rings 35 | 36 | ```{r example, fig.width=6, fig.height = 6} 37 | library(contouR) 38 | 39 | #set up your data 40 | setup = contour_grid(grid_size = 30, point_dist = .25, 41 | z_method = "runif", z = 1, z_span = 3) %>% 42 | contour_shape(radius = 10.2, 43 | x_center = 7, y_center = 7) 44 | 45 | # plot your data 46 | contour_plot(setup$grid_shape) + 47 | ggplot2::xlim(1, 30) + 48 | ggplot2::ylim(1, 30) 49 | ``` 50 | 51 | ## Example: with rings 52 | 53 | ```{r example-rings, fig.width=6, fig.height = 6} 54 | #set up your data 55 | setup = contour_grid(grid_size = 30, point_dist = .25, 56 | z_method = "runif", z = 1, z_span = 3) %>% 57 | contour_shape(radius = 10.2, 58 | x_center = 10, y_center = 10, 59 | ring_system = "multiple", 60 | num_rings = 10) 61 | 62 | # plot your data 63 | contour_plot(setup$grid_shape, setup$rings) + 64 | ggplot2::xlim(1, 30) + 65 | ggplot2::ylim(1, 30) 66 | ``` 67 | 68 | ## Example: without contour shape 69 | ```{r example-no-circle, fig.width=6, fig.height = 6} 70 | #set up your data 71 | setup = contour_grid(grid_size = 30, point_dist = .25, 72 | z_method = "runif", z = 1, z_span = 3) 73 | 74 | # plot your data 75 | contour_plot(setup) + 76 | ggplot2::xlim(1, 30) + 77 | ggplot2::ylim(1, 30) 78 | ``` 79 | -------------------------------------------------------------------------------- /R/helpers.R: -------------------------------------------------------------------------------- 1 | # Internal functions operating the contour_*() functions 2 | 3 | 4 | # calculate the distance between points 5 | distance_formula = function(x2, x1, y2, y1){ 6 | dist = sqrt((x2 - x1)^2 + (y2 - y1)^2) 7 | 8 | return(dist) 9 | } 10 | 11 | # initiate the grid of points for contours 12 | initiate_grid = function(param){ 13 | grid_points = expand.grid( 14 | x = seq(1, param$grid_size, by = param$point_dist), 15 | y = seq(1, param$grid_size, by = param$point_dist)) 16 | 17 | return(grid_points) 18 | } 19 | 20 | # calculate z 21 | use_z_method = function(param){ 22 | if(param$z_method == "rnorm"){ 23 | stat_calc = stats::rnorm( 24 | dplyr::n(), 25 | mean = param$z, 26 | sd = param$z_span) 27 | 28 | } else if(param$z_method == "rpois"){ 29 | stat_calc = stats::rpois( 30 | dplyr::n(), 31 | lambda = param$z) 32 | 33 | } else if(param$z_method == "runif"){ 34 | stat_calc = stats::runif( 35 | dplyr::n(), 36 | min = param$z - param$z_span, 37 | max = param$z + param$z_span 38 | ) 39 | } else if(param$z_method == "sample"){ 40 | stat_calc = sample( 41 | x = param$z:(param$z + param$z_span), 42 | size = dplyr::n(), 43 | replace = TRUE) 44 | } 45 | return(stat_calc) 46 | } 47 | 48 | 49 | calculate_z = function(grid_points, param){ 50 | 51 | grid_points = grid_points %>% 52 | dplyr::mutate(z = use_z_method(param)) 53 | 54 | return(grid_points) 55 | } 56 | 57 | # modify the output grid to be in a shape 58 | create_shape = function(grid_points, param){ 59 | grid_points = grid_points %>% 60 | dplyr::mutate(distance = distance_formula(param$x_center, .data$x, param$y_center, .data$y)) %>% 61 | dplyr::filter(.data$distance < param$radius) %>% 62 | dplyr::select(-.data$distance) 63 | 64 | return(grid_points) 65 | } 66 | 67 | # add rings to the shape 68 | create_multiple_rings = function(param){ 69 | parts = 10 70 | val = pi/parts 71 | start_ops = val * 1:parts 72 | ring_system = list() 73 | 74 | for(i in 1:param$num_rings){ 75 | start = sample(start_ops, 1) 76 | end = sample(1:(parts/2), size = 1) 77 | size = sample(param$radius:(param$radius + param$num_rings), size = 1) 78 | 79 | len = seq(start, start*end, length.out = 100) 80 | 81 | ring_system[[i]] = dplyr::tibble( 82 | x = (sin(len)*size) + param$x_center, 83 | y = (cos(len)*size) + param$y_center, 84 | group = LETTERS[i], 85 | type = "multiple" 86 | ) 87 | } 88 | 89 | return(dplyr::bind_rows(ring_system)) 90 | } 91 | 92 | create_halo = function(param){ 93 | len = seq(0, 2*pi, length.out = 500) 94 | 95 | ring_system = dplyr::tibble( 96 | x = (cos(len)*(param$radius + 4)) + param$x_center, 97 | y = (sin(len)*(param$radius + 4)) + param$y_center, 98 | group = LETTERS[1], 99 | type = "halo" 100 | ) 101 | 102 | return(ring_system) 103 | } 104 | 105 | 106 | 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /R/contour_plot.R: -------------------------------------------------------------------------------- 1 | #' Plot the contour grid 2 | #' 3 | #' @param grid_shape a dataframe of x, y, and z points 4 | #' @param rings a dataframe of x, y, and group points 5 | #' @param background_col a character string used for the background color of the plot 6 | #' @param line_col a character string used for the line colors of your plot 7 | #' 8 | #' @return a ggplot2 object with some default parameters of line size of 0.25, 9 | #' linejoin is round, and uses theme_void() to remove extra elements 10 | #' 11 | #' @export 12 | #' @importFrom rlang .data 13 | contour_plot = function(grid_shape, 14 | rings = NA, 15 | background_col = "#2a3c4b", 16 | line_col = "#e9ebed"){ 17 | 18 | if(!is.data.frame(grid_shape)){stop("grid_shape must be a dataframe")} 19 | if(!is.character(background_col)){stop("background_col must be a character string")} 20 | if(!is.character(line_col)){stop("line_col must be a character string")} 21 | 22 | # controlling mapping for optional rings 23 | if(is.data.frame(rings) == TRUE){ 24 | if(unique(rings$type) == "halo"){ 25 | mapping = ggplot2::aes( 26 | x = .data$x, 27 | y = .data$y, 28 | size = 4, 29 | alpha = 0.3) 30 | } else if(unique(rings$type) == "multiple"){ 31 | mapping = ggplot2::aes( 32 | x = .data$x, 33 | y = .data$y, 34 | group = .data$group, 35 | size = .25) 36 | } 37 | } 38 | 39 | 40 | 41 | # creating plots 42 | if(is.data.frame(rings) == FALSE){ 43 | output_shape = ggplot2::ggplot(data = grid_shape) + 44 | ggplot2::geom_contour(ggplot2::aes(x = .data$x, y = .data$y, z = .data$z), 45 | size = .25, 46 | linejoin = "round", 47 | color = line_col) + 48 | ggplot2::coord_equal(expand = c(0)) + 49 | ggplot2::theme_void() + 50 | ggplot2::theme(panel.background = 51 | ggplot2::element_rect(fill = background_col, 52 | color = background_col), 53 | plot.background = 54 | ggplot2::element_rect(fill = background_col, 55 | color = background_col)) 56 | } else { 57 | 58 | output_shape = ggplot2::ggplot() + 59 | ggplot2::geom_contour(data = grid_shape, 60 | ggplot2::aes(x = .data$x, y = .data$y, z = .data$z), 61 | size = .25, 62 | linejoin = "round", 63 | color = line_col) + 64 | ggplot2::geom_path(data = rings, 65 | mapping = mapping, 66 | color = line_col, 67 | linejoin = "round") + 68 | ggplot2::scale_alpha_identity() + 69 | ggplot2::scale_size_identity() + 70 | ggplot2::coord_equal(expand = c(0)) + 71 | ggplot2::theme_void() + 72 | ggplot2::theme(legend.position = "none", 73 | panel.background = 74 | ggplot2::element_rect(fill = background_col, 75 | color = background_col), 76 | plot.background = 77 | ggplot2::element_rect(fill = background_col, 78 | color = background_col)) 79 | } 80 | 81 | 82 | return(output_shape) 83 | 84 | 85 | } 86 | --------------------------------------------------------------------------------