Skip to content

Commit

Permalink
Issue 35: Add hex sticker (#36)
Browse files Browse the repository at this point in the history
* Add code to generate hex sticker and resulting .png file

* Fix linting issues

* Remove URL from logo

* Regenerate logo
  • Loading branch information
athowes authored May 15, 2024
1 parent be43bba commit 53f81f9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
46 changes: 41 additions & 5 deletions inst/make_hexsticker.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,50 @@ library(ggplot2)
# font setup
font_add_google("Zilla Slab Highlight", "useme")


# make standard plot
plot
outbreak <- simulate_gillespie(seed = 101)

secondary_dist <- data.table(
meanlog = 1.8, sdlog = 0.5
) |>
add_natural_scale_mean_sd()

obs <- outbreak |>
simulate_secondary(
meanlog = secondary_dist$meanlog[[1]],
sdlog = secondary_dist$sdlog[[1]]
) |>
observe_process()

truncated_obs <- obs |>
filter_obs_by_obs_time(obs_time = 25)

truncated_obs <- truncated_obs[sample(seq_len(.N), 200, replace = FALSE)]

combined_obs <- combine_obs(truncated_obs, obs)
meanlog <- secondary_dist$meanlog[[1]]
sdlog <- secondary_dist$sdlog[[1]]

plot <- combined_obs |>
ggplot() +
aes(x = delay_daily) +
geom_histogram(
aes(y = after_stat(density), fill = obs_at),
binwidth = 1, position = "dodge"
) +
lims(x = c(0, 18))

if (!missing(meanlog) && !missing(sdlog)) {
plot <- plot +
stat_function(
fun = dlnorm, args = c(meanlog, sdlog), n = 100,
col = "#696767b1"
)
}

# strip out most of the background
hex_plot <- plot +
scale_x_continuous(breaks = NULL) +
scale_fill_brewer(palette = "Blues", direction = 1) +
scale_y_continuous(breaks = NULL) +
labs(x = "", y = "") +
theme_void() +
Expand All @@ -28,11 +65,10 @@ sticker(
s_x = 1,
s_y = 0.85,
s_width = 1.3,
s_height = 0.85,
s_height = 0.75,
h_fill = "#ffffff",
h_color = "#646770",
filename = file.path("man", "figures", "logo.png"),
url = "epidist.epinowcast.org",
u_color = "#646770",
u_size = 3.5
)
Binary file added man/figures/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 53f81f9

Please sign in to comment.