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))
相关推荐
Chef_Chen15 小时前
从0开始学习R语言--Day49--Lasso-Cox 回归
学习·回归·r语言
Rita的程序bug1 天前
R语言基础| 基本图形绘制(条形图、堆积图、分组图、填充条形图、均值条形图)
开发语言·信息可视化·r语言
青春不败 177-3266-05203 天前
基于现代R语言【Tidyverse、Tidymodel】的机器学习方法与案例分析实践技术应用
深度学习·机器学习·支持向量机·r语言·集成算法
医工交叉实验工坊4 天前
R 语言绘制 10 种精美火山图:转录组差异基因可视化
python·信息可视化·r语言
智算菩萨4 天前
传统机器学习在信用卡交易预测中的卓越表现:从R²=-0.0075到1.0000的华丽转身
人工智能·机器学习·r语言
2201_753054895 天前
应用回归分析,R语言,多元线性回归总结(下)
回归·r语言·线性回归
LabEx8 天前
科研数据可视化核心技术:基于 AI 与 R 语言的热图、火山图及网络图绘制实践指南
人工智能·信息可视化·r语言·r语言绘图·乐备实·labex·科研数据绘图
Jet45058 天前
第100+43步 ChatGPT学习:R语言实现特征选择曲线图
学习·chatgpt·r语言
Chef_Chen8 天前
从0开始学习R语言--Day40--Kruskal-Wallis检验
开发语言·学习·r语言
quant_19868 天前
R语言如何接入实时行情接口
开发语言·经验分享·笔记·python·websocket·金融·r语言