相关文章推荐
性感的酱牛肉  ·  中共福建省委 ...·  6 月前    · 
重情义的青椒  ·  Accelerate model on ...·  8 月前    · 
淡定的打火机  ·  合肥市区高考考点公布!_合肥市瑶海区人民政府·  1 年前    · 
听话的马克杯  ·  学院新闻-继续教育与教师培训学院·  2 年前    · 
绅士的灭火器  ·  【粤剧小百科】(104)外、小、贴、夫、杂_行当·  2 年前    · 
Code  ›  R语言ggplot2一幅好看的气泡图及非常舒服的配色开发者社区
r语言 plot
https://cloud.tencent.com/developer/article/2009264
深情的青蛙
3 年前
作者头像
用户7010445
0 篇文章

R语言ggplot2一幅好看的气泡图及非常舒服的配色

前往专栏
腾讯云
开发者社区
文档 意见反馈 控制台
首页
学习
活动
专区
工具
TVP
文章/答案/技术大牛
发布
首页
学习
活动
专区
工具
TVP
返回腾讯云官网
社区首页 > 专栏 > 小明的数据分析笔记本 > R语言ggplot2一幅好看的气泡图及非常舒服的配色

R语言ggplot2一幅好看的气泡图及非常舒服的配色

作者头像
用户7010445
发布 于 2022-05-23 15:59:34
1.4K 0
发布 于 2022-05-23 15:59:34
举报

数据代码来源

https://github.com/emilmalta/30daychartchallenge/blob/master/script/22_animation.R

这个代码是利用gganimate这个R包做了一个动态的气泡图,结果非常惊艳

今天的推文主要学习其中做气泡图的代码和非常舒服的配色

加载需要用到的R包

library(tidyverse)
library(gganimate)
library(ggplot2)

读取数据集

这里我只选取原始代码数据集中的一小部分

dat01<-readr::read_csv("20220522.csv")

准备配色

cols <- c(
  "Africa" = "#34a186",
  "Americas" = "#f9cb45",
  "Asia" = "#b5182b",
  "Europe" = "#4cb1c4",
  "Oceania" = "#ab96d2"

作图代码

pdf(file = "abc1.pdf",
    width = 20,height = 20)
dat01 %>% 
  arrange(desc(sp_pop_totl)) %>% 
  ggplot(aes(x = it_mlt_main_p2, 
             y = it_cel_sets_p2, 
             label = country)) +
  geom_point(
    aes(size = sp_pop_totl, fill = continent), 
    pch = 21, color = "white", alpha = .9
  scale_fill_manual(values = cols) +
  scale_size_area(max_size = 80) +
  coord_cartesian(xlim = c(0, 75), ylim = c(0, 200), clip = "off") +
  guides(size = "none") +
  theme_minimal(base_family = "serif", base_size = 35) +
  theme(
    text = element_text(color = "#3a3e4c"), 
    plot.background = element_rect(fill = "#f2ebe7", color = NA), 
    panel.grid = element_line(linetype = 3, color = "#c9c8c4"),
    plot.title.position = "plot", 
    plot.title = element_text(size = 100),
    plot.subtitle = element_text(family = "serif"),
    legend.position = "bottom", plot.margin = margin(20,20,20,20)
  guides(size = "none", fill = guide_legend(title = NULL, override.aes = list(size = 5))) +
  labs(title = "Rise of Cell Phones", 
       subtitle = "Cell phones are not only more convenient for the end user. They are also much easier to implement in\nregions with poor infrastructure. Countries with low income never saw the rise of landline phones, but\nachieved widespread use of cell phones within two decades",
 
推荐文章
性感的酱牛肉  ·  中共福建省委 福建省人民政府印发《关于加强基层治理体系和治理能力现代化建设的实施方案》 _ 省级 _ 福建省发展和改革委员会
6 月前
重情义的青椒  ·  Accelerate model on Hexagon (Snapdragon accelerator) - Mobile - PyTorch Forums
8 月前
淡定的打火机  ·  合肥市区高考考点公布!_合肥市瑶海区人民政府
1 年前
听话的马克杯  ·  学院新闻-继续教育与教师培训学院
2 年前
绅士的灭火器  ·  【粤剧小百科】(104)外、小、贴、夫、杂_行当
2 年前
今天看啥   ·   Py中国   ·   codingpro   ·   小百科   ·   link之家   ·   卧龙AI搜索
删除内容请联系邮箱 2879853325@qq.com
Code - 代码工具平台
© 2024 ~ 沪ICP备11025650号