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))
相关推荐
亚图跨际1 小时前
MATLAB和Python及R潜变量模型和降维
python·matlab·r语言·生物学·潜变量模型
写点什么啦3 小时前
使用R语言survminer获取生存分析高风险和低风险的最佳截断值cut-off
开发语言·python·r语言·生存分析·x-tile
让学习成为一种生活方式20 小时前
R包下载太慢安装中止的解决策略-R语言003
java·数据库·r语言
有梦想的Frank博士2 天前
R语言*号标识显著性差异判断组间差异是否具有统计意义
开发语言·信息可视化·r语言
逆风远航5 天前
R语言贝叶斯:INLA下的贝叶斯回归、生存分析、随机游走、广义可加模型、极端数据的贝叶斯分析
开发语言·r语言·贝叶斯·生态学·结构方程·环境科学·混合效应
Faxxtty5 天前
【R语言】解决package ‘qvalue’ is not available (for R version 3.6.1)
开发语言·r语言
Cachel wood6 天前
Vue前端框架:Vue前端项目文件目录
java·前端·vue.js·python·算法·r语言·前端框架
邢博士谈科教6 天前
OmicsTools软件和R语言分析环境安装配置答疑汇总最新版
r语言
纪伊路上盛名在7 天前
vscode中提升效率的插件扩展——待更新
linux·服务器·ide·vscode·python·r语言·编辑器
拓端研究室TRL7 天前
银行信贷风控专题:Python、R 语言机器学习数据挖掘应用实例合集:xgboost、决策树、随机森林、贝叶斯等...
python·决策树·机器学习·数据挖掘·r语言