carousel <- function(fn="Rplots.pdf") {
stopifnot(require(ggplot2))
stopifnot(require(aRtsy))
stopifnot(require(meme))
stopifnot(require(ggwordcloud))
stopifnot(require(gridExtra))
stopifnot(require(ggtext))
# page 1
set.seed(13)
title_colour <- colorPalette("mixer4")[3]
yellow <- colorPalette("mixer4")[1]
p1 <- canvas_flow(
colors = colorPalette("mixer4"),
polar=T, background = "#EFEFEF",
lwd=2
) +
ggtitle("Create Carousel\nPosts with R") +
theme(plot.title = element_text(
face="bold", colour=title_colour, size=42, vjust=-0.5
)
) +
theme(plot.margin = unit(c(1,0.5,0,0), "cm"))
# page 2
tools <- data.frame(word=c(
"Photoshop", "Canva", "Visme", "Spark", "Design Wizard", "Easil",
"Snappa", "Crello", "Stencil", "PicMonkey", "Vectornator", "Visme",
"Stencil", "Snappa", "Piktochart", "Design Wizard", "Easil", "Pixelied",
"Tyle", "Pixlr", "Fotojet", "Fotor", "Venngage", "PicMonkey",
"Desygner", "Figma", "Penpot", "Affinity Publisher", "Vectr", "InDesign",
"Fireworks", "Polotno Studio", "Genially", "PicMonkey", "Corel Vector",
"PosterMyWall", "PixTeller", "VistaCreate", "Venngage", "Simplified",
"reThumbnail", "Cretorial", "Lucidpress", "Baseline", "Picofme.io",
"EvolveUI", "Drawtify", "VivaDesigner", "Pikiz", "Tallery Gallery",
"MockoFun", "Picmaker", "Plasfy", "APITemplate.io", "SoVisual.co",
"Pozters", "Mediamodifier", "Dezo", "365Layouts.com", "Sprightly",
"Etimat Designer"
))
p2 <- ggplot(tools, aes(
label = word,
color = factor(sample(5, nrow(tools), replace = T))
)) +
scale_colour_manual(values=colorPalette("mixer4")) +
geom_text_wordcloud_area(shape="square") +
scale_size_area(max_size = 8) + theme_minimal() +
ggtitle("If you think you \nneed a special tool...") +
theme(plot.title = element_text(
face="bold", colour=title_colour, size=42, vjust=-0.5
)) +
theme(plot.margin = unit(c(1,0.5,0,0.5), "cm"))
# page 3
dat <- data.frame(x = 1, y = 1,
label = paste0(
"It's just a PDF!
",
paste0(
"@ 1080x1080px.
It always has been."
)
)
)
p3 <- ggplot(dat) +
ggtext::geom_textbox(
aes(x = x, y = y, label = label), box.colour = NA, width = unit(10, "cm"),
fill=yellow
) +
theme_void() +
theme(
panel.background = element_rect(fill = yellow, colour = NA, size = 0),
panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank()
) +
ggtitle("... then you are mistaken:") +
theme(plot.title = element_text(
face="bold", colour=title_colour, size=42, vjust=-0.5
)) +
theme(plot.margin = unit(c(1,0.5,0,0.5), "cm")) +
theme(plot.background = element_rect(fill = yellow))
# page 4
credits <- c(
"aRtsy: Generative Art with 'ggplot2'",
"ggwordcloud: A Word Cloud Geom for 'ggplot2'",
"ggtext: Improved Text Rendering Support for 'ggplot2'"
)
n_lines <- length(credits)
dat <- data.frame(x = 1, y=n_lines:1, label = credits)
p4 <- ggplot(dat) +
ggtext::geom_textbox(
aes(x = x, y = y, label = label),
box.colour = NA, width=unit(500, "pt"), fill="#EFEFEF",
size=8
) + ylim(-2, n_lines+2) +
theme_void() +
ggtitle("Credits") +
theme(plot.title = element_text(
face="bold", colour=title_colour, size=42, vjust=-0.5
)) +
theme(plot.margin = unit(c(1,0.5,0,0.5), "cm"))
# save it
res <- marrangeGrob(list(p1, p2, p3, p4), nrow=1, ncol=1, top=NULL)
ggsave(fn,
plot=res, device="pdf", width=1080, height=1080, units="px", dpi=72,
bg="#EFEFEF", scale=0.5
)
}