Skip to content

Commit d725a62

Browse files
authored
Merge pull request #35 from nrennie/develop
Develop
2 parents e98cc95 + fd74092 commit d725a62

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+287
-80
lines changed

.Rbuildignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
^aRt\.Rproj$
22
^\.Rproj\.user$
33
.lintr
4-
images/
54
aRt.png
5+
^_pkgdown\.yml$
6+
^docs$
7+
^pkgdown$

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.Rproj.user
22
.Rhistory
3-
nrennie_aRt/rsconnect
3+
nrennie_aRt/rsconnect
4+
docs

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: aRt
22
Title: Generative Art with R
3-
Version: 1.1.7
3+
Version: 1.1.8
44
Authors@R:
55
person(given = "Nicola",
66
family = "Rennie",

NAMESPACE

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export(shells)
2121
export(spirals)
2222
export(static)
2323
export(stripes)
24+
export(sunbursts)
25+
export(sunbursts_panel)
2426
export(theme_aRt)
2527
export(tiles)
2628
export(vortex)

NEWS.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# aRt
22

3+
# aRt 1.1.8
4+
5+
* add `sunbursts()` function
6+
* add panel function
7+
* add {pkgdown website}
8+
39
# aRt 1.1.7
410

511
* add GitHub actions

R/globalVariables.R

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
globalVariables(c("..density.."))

R/sunbursts.R

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#' Sunbursts
2+
#'
3+
#' This function generates a generative art ggplot object from 2d density plots
4+
#'
5+
#' @param n Granularity. Default 100.
6+
#' @param x_means Vector of any number of means for the x-coordinate. Default c(0, 10, 5).
7+
#' @param y_means Vector of any number of means for the y-coordinate. Default c(0, 7, 8).
8+
#' @param xy_var Numeric varaince of x and y points. Default 5.
9+
#' @param low Colour of background. Default "#074050".
10+
#' @param high Colour of sunburst points. Default "#d3f2a3".
11+
#' @param s Seed value. Default 1234.
12+
#' @return A ggplot object.
13+
#' @export
14+
15+
sunbursts <- function(n = 100,
16+
x_means = c(0, 10, 5),
17+
y_means = c(0, 7, 8),
18+
xy_var = 5,
19+
low = "#074050",
20+
high = "#d3f2a3",
21+
s = 1234) {
22+
set.seed(s)
23+
# generate data
24+
df <- purrr::map2(.x = x_means,
25+
.y = y_means,
26+
.f = ~data.frame(x = rnorm(n, .x, xy_var), y = rnorm(n, .y, xy_var)))
27+
plot_data <- dplyr::bind_rows(df)
28+
# plot
29+
p <- ggplot2::ggplot(data = plot_data,
30+
mapping = ggplot2::aes(x = .data$x, y = .data$y)) +
31+
ggplot2::stat_density_2d(mapping = ggplot2::aes(fill = ..density..),
32+
geom = "raster", contour = FALSE, na.rm = TRUE) +
33+
ggplot2::scale_x_continuous(expand = c(0, 0),
34+
limits = c(min(c(plot_data$x, plot_data$y)),
35+
(max(c(plot_data$x, plot_data$y))))) +
36+
ggplot2::scale_y_continuous(expand = c(0, 0),
37+
limits = c(min(c(plot_data$x, plot_data$y)),
38+
(max(c(plot_data$x, plot_data$y))))) +
39+
ggplot2::scale_fill_gradient(low = low, high = high) +
40+
ggplot2::coord_fixed() +
41+
ggplot2::theme_void() +
42+
ggplot2::theme(legend.position = "none",
43+
plot.margin = ggplot2::unit(c(-0.5, -0.5, -0.5, -0.5), "cm"),
44+
plot.background = ggplot2::element_rect(fill = low, colour = low),
45+
panel.background = ggplot2::element_rect(fill = low, colour = low))
46+
p
47+
}

R/sunbursts_panel.R

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#' Sunbursts panel
2+
#'
3+
#' This function generates a grid of sunbursts pieces
4+
#'
5+
#' @param n Granularity. Default 100.
6+
#' @param ncol Number of column panels. Default 4.
7+
#' @param nrow Number of row panels. Default 4.
8+
#' @param x_means Vector of any number of means for the x-coordinate. Default c(0, 10, 5).
9+
#' @param y_means Vector of any number of means for the y-coordinate. Default c(0, 7, 8).
10+
#' @param xy_var Numeric varaince of x and y points. Default 5.
11+
#' @param low Colour of background. Default "#4e0550".
12+
#' @param high Colour of sunburst points. Default "#facdfc".
13+
#' @param s Seed value. Default 1234.
14+
#' @return A ggplot object.
15+
#' @export
16+
#'
17+
18+
sunbursts_panel <- function(n = 100,
19+
ncol = 4,
20+
nrow = 4,
21+
x_means = c(0, 10, 5),
22+
y_means = c(0, 7, 8),
23+
xy_var = 5,
24+
low = "#4e0550",
25+
high = "#facdfc",
26+
s = 1234) {
27+
set.seed(s)
28+
ss <- sample(5:100, size = ncol * nrow)
29+
p <- lapply(ss, function(i) sunbursts(n = i,
30+
x_means = x_means,
31+
y_means = y_means,
32+
xy_var = xy_var,
33+
low = low,
34+
high = high,
35+
s = i))
36+
patchwork::wrap_plots(p) +
37+
patchwork::plot_layout(ncol = ncol, nrow = nrow) &
38+
ggplot2::theme(plot.margin = ggplot2::unit(c(-0.5, -0.5, -0.5, -0.5), "cm"),
39+
plot.background = ggplot2::element_rect(fill = low, colour = low),
40+
panel.background = ggplot2::element_rect(fill = low, colour = low))
41+
42+
}

0 commit comments

Comments
 (0)