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))
相关推荐
pk_xz12345610 小时前
R 和 Origin 完成细菌 OTU 表、土壤理化性质数据的微生物 Beta 多样性分析
算法·机器学习·r语言
乄北城以北乀12 小时前
第1章 R语言中的并行处理入门
开发语言·分布式·r语言
生信圆桌1 天前
【生信圆桌x教程系列】如何安装 seurat V4版本R包
开发语言·r语言
赵钰老师2 天前
基于R语言APSIM模型应用及批量模拟(精细农业、水肥管理、气候变化、粮食安全、土壤碳周转、环境影响、农业可持续性、农业生态等)
开发语言·数据分析·r语言
赵钰老师3 天前
【R语言遥感技术】“R+遥感”的水环境综合评价方法
开发语言·数据分析·r语言
生信圆桌3 天前
【生信圆桌x教程系列】如何安装 seurat V5版本R包,最详细安装手册
开发语言·r语言
Biomamba生信基地3 天前
R语言基础| 功效分析
开发语言·python·r语言·医药
数据分析能量站3 天前
目标检测-R-CNN
目标检测·r语言·cnn
matlabgoodboy4 天前
数据分析帮做spss数据代分析stata实证python统计R语言eviews处理
python·数据分析·r语言
biomooc4 天前
R 语言 | 绘图的文字格式(绘制上标、下标、斜体、文字标注等)
开发语言·r语言