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))
相关推荐
Yolo566Q7 小时前
R语言、BIOMOD2丨物种分布模型研究进展与挑战
r语言
岁月如歌,青春不败12 小时前
MaxEnt模型全解析:从原理到 R 语言实战,开启生态环境研究新视野
arcgis·r语言·生态学·论文写作·生态系统服务·物种分布·maxent模型
invincible_Tang1 天前
R格式 (15届B) 高精度
开发语言·算法·r语言
KY_chenzhao1 天前
基于R语言与MaxEnt的物种分布建模全流程解析:从算法优化到科研制图实战
r语言·maxent·气候变化·物种分布
tRNA做科研1 天前
通过Bioconductor/BiocManager安装生物r包详解(问题汇总)
开发语言·r语言·生物信息学·bioconductor·biocmanager
Tiger Z1 天前
R 语言科研绘图 --- 韦恩图-汇总
开发语言·程序人生·r语言·贴图
Biomamba生信基地2 天前
R语言入门课| 04 R语言基本函数
开发语言·r语言·生信
十三画者3 天前
【工具】BioPred一个用于精准医疗中生物标志物分析的 R 软件包
数据挖掘·数据分析·r语言·数据可视化
小艳加油3 天前
MaxEnt物种分布建模全流程;R+ArcGIS+MaxEnt模型物种分布模拟、参数优化方法、结果分析制图与论文写作
arcgis·r语言·物种分布模拟·maxent模型
weixin_贾3 天前
MaxEnt模型进阶:基于R语言自动化与GIS空间建模的物种栖息地精准预测
r语言·生物多样性·物种分布