library(sysfonts)
font_add_google("Anton", "anton")
showtext_auto()
# ---- data prep ----
plot_df <- top_10_movie |>
mutate(
Title = ifelse(rank == 10, "THE GREAT FLOOD", as.character(Title)),
title_upper = toupper(Title),
views_m = as.numeric(views_m),
# compress the range so smaller titles show more difference
bar_len = scales::rescale(log10(views_m), to = c(0.55, 1.00)),
# y positions so rank 1 is at top
y = rev(rank)
)
# ---- helper: true rounded-corner rectangle as polygon ----
rounded_rect_df <- function(id, xmin, xmax, ymin, ymax, r = 0.03, n = 25) {
r <- min(r, (xmax - xmin)/2, (ymax - ymin)/2)
arc <- function(cx, cy, start, end) {
t <- seq(start, end, length.out = n)
tibble(x = cx + r * cos(t), y = cy + r * sin(t))
}
top <- tibble(x = seq(xmax - r, xmin + r, length.out = 2), y = ymax)
left <- tibble(x = xmin, y = seq(ymax - r, ymin + r, length.out = 2))
bottom <- tibble(x = seq(xmin + r, xmax - r, length.out = 2), y = ymin)
right <- tibble(x = xmax, y = seq(ymin + r, ymax - r, length.out = 2))
pts <- bind_rows(
arc(xmax - r, ymax - r, 0, pi/2), # top-right
top,
arc(xmin + r, ymax - r, pi/2, pi), # top-left
left,
arc(xmin + r, ymin + r, pi, 3*pi/2), # bottom-left
bottom,
arc(xmax - r, ymin + r, 3*pi/2, 2*pi), # bottom-right
right
)
pts |> mutate(group = id)
}
# build polygon data for all 10 bars
bar_poly <- plot_df |>
rowwise() |>
do(rounded_rect_df(
id = .$rank,
xmin = 0.10,
xmax = .$bar_len,
ymin = .$y - 0.45,
ymax = .$y + 0.45,
r = 0.03, # increase for more rounding, decrease for less
n = 25
)) |>
ungroup()
# ---- plot ----
most_watched_movies_plot <- ggplot() +
coord_cartesian(xlim = c(0, 1.35), ylim = c(0.5, 11.5), clip = "off") +
theme_void() +
theme(
panel.background = element_rect(fill = "red", color = NA),
plot.background = element_rect(fill = "red", color = NA),
plot.margin = margin(12, 25, 10, 15)
) +
# rounded bars
geom_polygon(
data = bar_poly,
aes(x = x, y = y, group = group),
fill = "white", color = "red", linewidth = 2
) +
# rank numbers (no box)
geom_text(
data = plot_df,
aes(x = 0.05, y = y, label = rank),
family = "anton", fontface = "bold",
color = "black", size = 9
) +
# titles
geom_text(
data = plot_df,
aes(x = 0.12, y = y, label = title_upper),
hjust = 0,
family = "anton", fontface = "bold",
color = "black", size = 10
) +
# value labels beside bar end
geom_text(
data = plot_df,
aes(x = bar_len + 0.03, y = y, label = views_label),
hjust = 0,
family = "anton", fontface = "bold",
color = "black", size = 10
) +
# NETFLIX top-left
annotate(
"text", x = 0.01, y = 11.45, label = "NETFLIX",
hjust = 0, vjust = 1,
family = "anton", fontface = "bold",
color = "white", size = 10
) +
# bottom-right block
annotate(
"text", x = Inf, y = -Inf, label = "MOST-WATCHED\nMOVIES",
hjust = 1.02, vjust = -0.2,
family = "anton", fontface = "bold",
color = "black", size = 14, lineheight = 0.7
)
most_watched_movies_plot