Skip to content
0

Where to focus a marketing campaign?

📖 Background

You are a data analyst at a crowdfunding site. For the next quarter, your company will be running a marketing campaign. The marketing manager wants to target those segments that have donated the most in the past year. She turned to you to help her with her upcoming meeting with the CEO.

library(tidyverse)
library(dplyr)
install.packages("ggpubr", quiet = TRUE)
library(ggpubr)
library(png)
library(grid)
library(patchwork)
library(RCurl)
library(cowplot)
install.packages("kableExtra", quiet = TRUE)
library(kableExtra)

df <- readr::read_csv('./data/crowdfunding.csv', progress = FALSE)

1) What are the top three categories in terms of total donations?

Run cancelled
df1 <- df %>%
  group_by(category) %>%
  summarise(Amount_tot_category = sum(amount))
kbl(df1) %>%
  kable_styling(bootstrap_options = c("striped", "hover"))
df1 <- df1[-c(1,2),]

2) What device type has historically provided the most contributions?

Run cancelled
df2 <- df %>%
  group_by(device) %>%
  summarise(Amount_tot_device = sum(amount))
kbl(df2) %>%
  kable_styling(bootstrap_options = c("striped", "hover"))

3) What age bracket should the campaign target?

library(dplyr)
library(knitr)
library(kableExtra)

# Assuming df is already defined and is a data frame
df3 <- df %>%
  group_by(age) %>%
  summarise(Amount_tot_age = sum(amount, na.rm = TRUE))

kbl(df3) %>%
  kable_styling(bootstrap_options = c("striped", "hover"))

4) Visualize the results

# Ensure necessary libraries are loaded
library(ggplot2)
library(grid)
library(png)
library(RCurl)
library(cowplot)

# Sample data creation for df1, df2, and df3
df1 <- data.frame(category = c("A", "B", "C"), Amount_tot_category = c(165000, 162000, 160000))
df2 <- data.frame(device = c("iOS", "Android"), Amount_tot_device = c(530525, 283545))
df3 <- data.frame(age = c("18-24", "25-34", "35-44"), Amount_tot_age = c(300000, 400000, 500000))

# plots 
df1$category <- as.factor(df1$category)
p1 <- ggplot() +
  geom_label(data = df1, mapping = aes(x = reorder(category, -Amount_tot_category), y = Amount_tot_category, label = Amount_tot_category), fill = c("gold", "slategray2", "#AD8A56")) +
  theme_classic() +
  theme(axis.title.x = element_blank(),
        axis.text.y = element_blank(),
        axis.ticks.y = element_blank(),
        text = element_text(size = 10),
        axis.text.x = element_text(size = 10, color = "black")) + 
  ylab("TOT. Amount") + ylim(160000, 167000)

imgurl <- "https://pic.onlinewebfonts.com/svg/img_204828.png"
ios_image <- readPNG(getURLContent(imgurl), native = TRUE)

gpp <- rasterGrob(ios_image, interpolate = TRUE)
gpp$width <- unit(2, "cm") 
gpp$height <- unit(2, "cm")

imgurl <- "https://cdn.pixabay.com/photo/2017/01/31/17/43/android-2025857_960_720.png"
and_image <- readPNG(getURLContent(imgurl), native = TRUE)

gpp2 <- rasterGrob(and_image, interpolate = TRUE)
gpp2$width <- unit(2, "cm") 
gpp2$height <- unit(2, "cm")

df2$device <- 1:2
p2 <- ggplot() + 
  theme_classic() +
  annotation_custom(gpp, xmin = 1, xmax = 1, ymin = 530525, ymax = 530525) +
  annotation_custom(gpp2, xmin = 2, xmax = 2, ymin = 283545, ymax = 283545) +
  geom_label(data = df2, mapping = aes(x = reorder(device, -Amount_tot_device), y = Amount_tot_device, label = Amount_tot_device)) +
  theme(axis.title.x = element_blank(),
        axis.text.y = element_blank(),
        axis.text.x = element_blank(),
        axis.ticks.y = element_blank(),
        axis.ticks.x = element_blank(),
        text = element_text(size = 10),
        panel.ontop = TRUE,
        panel.background = element_rect(colour = NA, fill = "transparent")) + 
  ylab("TOT. Amount") + ylim(283545 - 100000, 530525 + 200000)

p3 <- ggplot() + 
  geom_bar(data = df3, mapping = aes(x = age, y = Amount_tot_age, fill = age), stat = "identity") +
  theme_classic() +
  theme(axis.title.x = element_blank(),
        axis.text.y = element_blank(),
        axis.ticks.y = element_blank(),
        text = element_text(size = 10),
        axis.text.x = element_text(size = 10, color = "black"),
        legend.position = "none") + 
  ylab("TOT. Amount") + ylim(0, 500000) +
  scale_fill_manual(values = c("18-24" = "orange"))

ggdraw() +
  draw_plot(p1, x = 0, y = .5, width = .5, height = .5) +
  draw_plot(p2, x = .5, y = .5, width = .5, height = .5) +
  draw_plot(p3, x = 0, y = 0, width = 1, height = 0.5) + 
  draw_plot_label(label = c("Top 3 Categories", "iOS vs Android", "Age Bracket Target"), size = 12,
                  x = c(0, 0.5, 0), y = c(1, 1, 0.5))