前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ggplot2基础绘图之哑铃图

ggplot2基础绘图之哑铃图

作者头像
R语言数据分析指南
发布2022-09-21 14:38:55
3560
发布2022-09-21 14:38:55
举报
文章被收录于专栏:R语言数据分析指南

❝本节来分享一个绘制哑铃图的小教程,里面细节满满;各位观众老爷细细品味,下面来看具体案例 ❞

导入数据

代码语言:javascript
复制
read_tsv("data.xls") %>% 
  distinct(country_name,.keep_all = T)

数据可视化

代码语言:javascript
复制
ggplot(aes(reorder(country_name, duration))) +
  geom_point(aes(y = start_year, col = continent), size = 5, show.legend = FALSE) +
  geom_point(aes(y = end_year, col = continent), size = 5, show.legend = FALSE) +
  geom_segment(aes(xend = country_name, y = start_year, yend = end_year, col = continent), size = 4) +
  geom_segment(aes(xend = country_name, y = start_year, yend = end_year), col = "white", size = 2) +
  geom_point(aes(y = start_year), size = 3, col = "white") +
  geom_point(aes(y = end_year), size = 3, col = "white") +
  geom_text(aes(y = 2023,label = paste(duration,"year")),color="black",size=3) +
  scale_y_continuous()+
  coord_flip() +
  scale_color_aaas()+
  labs(x = NULL, y = NULL, col = NULL) +
  theme(axis.title = element_blank(),
        axis.text.x=element_text(color="black",angle = 0,vjust=0.5, margin = margin(b =5)),
        axis.text.y = element_markdown(size = 10,hjust =1,color = "black"),
        panel.background = element_rect(fill = NA,color = NA),
        panel.grid.minor= element_line(size=0.2,color="#e5e5e5"),
        panel.grid.major = element_line(size=0.2,color="#e5e5e5"),
        panel.border = element_rect(fill=NA,color="black",size=1,linetype="solid"),
        legend.position = "top",
        legend.direction="horizontal",#"vertical"
        legend.title = element_blank(),
        legend.background=element_blank())
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2022-05-30,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 R语言数据分析指南 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 导入数据
  • 数据可视化
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档