R可视化:好看的气泡图

加载R包

R 复制代码
library(tidyverse)
library(camcorder)

gg_record(dir = "tidytuesday-temp", device = "png", width = 8, height = 8, units = "in", dpi = 320)

导入数据

R 复制代码
team_results <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2024/2024-03-26/team-results.csv') %>% 
  janitor::clean_names()

数据预处理

R 复制代码
f1 <- "Graphik"
f1b <- "Graphik Compact"
f2 <- "Produkt"
f2b <- "Produkt Medium"  


pal <- MetBrewer::met.brewer("Homer2")

tr <- team_results %>% 
  mutate(
    f4percent = parse_number(f4percent),
    champpercent = parse_number(champpercent)
  ) 

画图

R 复制代码
ggplot(tr, aes(pake, pase, label = str_wrap(team, 12))) +
  geom_vline(xintercept = 0) +
  geom_hline(yintercept = 0) +
  geom_abline(linetype = "dotted") +
  geom_point(aes(size = champpercent, color = f4percent), alpha = 0.7) +
  shadowtext::geom_shadowtext(data = . %>% filter(champpercent > 33), nudge_y = -0.5, family = f1b, color = "black", bg.color = "white", size = 4.5, lineheight = 0.9) +
  scale_color_stepsn(colors = pal) +
  scale_size_area(max_size = 10) +
  coord_fixed() +
  guides(
    size = guide_legend(reverse = TRUE, override.aes = list(color = pal[4])),
    color = guide_colorsteps(show.limits = TRUE)
    ) +
  labs(
    x = "Performance Against KenPom Expectation (PAKE)",
    y = "Performance Against Seed Expectation (PASE)",
    color = "Likelihood of getting to\nat least 1 Final Four",
    size = "Likelihood of winning\nat least 1 Championship",
    title = "NCAA Men's March Madness: Performance vs. Expectations",
    subtitle = "Data for 236 teams, from 2008 to 2024. The 2020 tournament was canceled due to Covid-19",
    caption = "Source: Nishaan Amin · Graphic: Georgios Karamanis"
  ) +
  theme_minimal(base_family = f1) +
  theme(
    legend.position = c(0.72, 0.13),
    legend.title = element_text(hjust = 1, margin = margin(0, 0, 10, 0)),
    legend.box = "horizontal",
    legend.key.width = unit(0.8, "line"),
    plot.background = element_rect(fill = "grey99", color = NA),
    plot.title = element_text(face = "bold"),
    plot.margin = margin(10, 10, 10, 10))
相关推荐
lishaoan7711 小时前
实验设计与分析(第6版,Montgomery)第3章单因子实验:方差分析3.11思考题3.6 R语言解题
r语言·统计分析·实验设计与分析·残差分析·单因子方差分析·正态性假设·tukeyhsd
南瓜胖胖13 小时前
【R语言编程绘图-折线图】
开发语言·r语言
Chef_Chen15 小时前
从0开始学习R语言--Day11--主成分分析
开发语言·学习·r语言
Biomamba生信基地19 小时前
R语言基础| 可视化初探(ggplot2)
r语言·可视化·生信·医药
开开心心就好2 天前
安卓实用复制功能增强工具
开发语言·javascript·python·qt·r语言·ocr·pygame
Chef_Chen2 天前
从0开始学习R语言--Day09--方差分析
开发语言·学习·r语言
开开心心就好2 天前
识别速度快且精准的OCR工具
开发语言·javascript·qt·r语言·ecmascript·ocr·bash
胖哥真不错2 天前
R基于逻辑回归模型实现心脏病检测及SHAP值解释项目实战
r语言·逻辑回归·项目实战·shap值解释·逻辑回归模型·心脏病检测
Chef_Chen2 天前
R语言学习--Day04--数据分析技巧
学习·数据分析·r语言
南瓜胖胖3 天前
R语言科研编程-柱状图
开发语言·r语言