R可视化:好看的气泡图

加载R包

library(tidyverse)
library(camcorder)

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

导入数据

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

数据预处理

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)
  ) 

画图

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))

在这里插入图片描述

  • 7
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

生信学习者2

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值