Skip to content

Commit 88d765d

Browse files
committed
w
1 parent 88c1707 commit 88d765d

23 files changed

Lines changed: 6261 additions & 1653 deletions

File tree

.DS_Store

0 Bytes
Binary file not shown.

Plot/.DS_Store

0 Bytes
Binary file not shown.

Plot/5 chart club.qmd

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,12 +443,119 @@ gg
443443
ggsave("budget_waffle.png", width = 6, height = 6.4)
444444
```
445445

446+
447+
448+
446449
## Resources
447450

448451
- [Riffomonas Code Club: Waffle Chart](https://riffomonas.org/code_club/2025-05-12-waffle)
449452
- [YouTube Tutorial: Creating this chart](https://www.youtube.com/watch?v=vtuyVTXmlPU&t=1s)
450453

451454

455+
456+
# perceptions of Trump's policies in LA
457+
458+
459+
```{r}
460+
library(tidyverse)
461+
library(showtext)
462+
library(ggtext)
463+
library(glue)
464+
library(ggimage)
465+
```
466+
467+
468+
469+
```{r}
470+
# Data
471+
data <- tribble(
472+
~category, ~count, ~color,
473+
"Support", 421, "#2ca7c4",
474+
"Unsure", 149, "#bfbfbf",
475+
"Oppose", 445, "#e87b34"
476+
) %>%
477+
mutate(percentage = paste0(round(count / sum(count) * 100), "%"))
478+
479+
480+
cols_per_group <- 18
481+
group_spacing <- 22
482+
483+
# Dot layout with centered bottom row
484+
dot_data <- data %>%
485+
uncount(weights = count) %>%
486+
group_by(category) %>%
487+
mutate(dot_id = row_number() - 1,
488+
row = dot_id %/% cols_per_group) %>%
489+
group_by(category, row) %>%
490+
mutate(
491+
dots_in_row = n(),
492+
start_col = floor((cols_per_group - dots_in_row) / 2),
493+
col = start_col + row_number() - 1
494+
) %>%
495+
ungroup()
496+
497+
spacing_factor <- 2.1
498+
499+
dot_data <- dot_data %>%
500+
mutate(
501+
group_index = match(category, unique(data$category)) - 1,
502+
x = (col + group_index * group_spacing) * spacing_factor,
503+
y = (-row - 6) * spacing_factor
504+
)
505+
506+
# Find max y per group (top dot in each group)
507+
label_y_positions <- dot_data %>%
508+
group_by(category) %>%
509+
summarize(max_y = max(y)) %>%
510+
arrange(match(category, data$category)) %>%
511+
pull(max_y)
512+
513+
# Put label slightly above top dot (adjust +3 or so)
514+
label_y_positions <- label_y_positions + 6
515+
516+
# X positions for labels (centered like before)
517+
label_x_positions <- c(8.5, 8.5 + group_spacing, 8.5 + group_spacing * 2) * spacing_factor
518+
519+
title_text <- "Do you support or oppose Trump\nsending the National Guard and\nMarines to respond to the L.A. protests?"
520+
title_x <- mean(range(dot_data$x))
521+
title_y <- max(dot_data$y) + 25
522+
```
523+
524+
525+
```{r}
526+
# Plot
527+
ggplot(dot_data, aes(x = x, y = y)) +
528+
geom_point(aes(color = category), size = 2.5) +
529+
scale_color_manual(values = setNames(data$color, data$category)) +
530+
coord_equal(clip = "off") +
531+
theme_void() +
532+
theme(
533+
legend.position = "none",
534+
plot.margin = margin(40, 30, 10, 30)
535+
) +
536+
geom_label(aes(x = title_x, y = title_y, label = title_text),
537+
size = 6,
538+
label.size = 0.8,
539+
fill = "white",
540+
color = "black",
541+
label.r = unit(0.25, "lines"),
542+
label.padding = unit(c(0.4, 0.7, 0.4, 0.7), "lines"),
543+
fontface = "bold",
544+
lineheight = 1.0) +
545+
annotate("text", x = label_x_positions[1], y = label_y_positions[1],
546+
label = paste0(data$category[1], "\n", data$percentage[1]), size = 5, fontface = "bold", hjust = 0.5) +
547+
annotate("text", x = label_x_positions[2], y = label_y_positions[2],
548+
label = paste0(data$category[2], "\n", data$percentage[2]), size = 5, fontface = "bold", hjust = 0.5) +
549+
annotate("text", x = label_x_positions[3], y = label_y_positions[3],
550+
label = paste0(data$category[3], "\n", data$percentage[3]), size = 5, fontface = "bold", hjust = 0.5)
551+
552+
```
553+
554+
555+
556+
557+
558+
452559
# Resources
453560

454561
- [Riffomonas Code Club: Multiracial Census Data](https://riffomonas.org/code_club/2021-08-13-multiracial_census_data)

Plot/sandp500_weekly.png

-368 Bytes
Loading

Publish/.DS_Store

0 Bytes
Binary file not shown.

_extensions/.DS_Store

6 KB
Binary file not shown.

_freeze/.DS_Store

0 Bytes
Binary file not shown.

_freeze/Plot/5 chart club/execute-results/html.json

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

_freeze/intro/1 basic R/execute-results/html.json

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)