0. 参考:
https://r-graph-gallery.com/web-circular-barplot-with-R-and-ggplot2.html
1. 说明:
利用 ggplot 绘制 环状的条形图 (circular barplot),并且每个条带按照数值大小进行排列。
2 绘图代码:
注意:绘图代码中的字体为 “Times New Roman”,如果没有这个字体的话,可以更换为其他字体,或者用下面代码加载改字体:
## 加载字体
library(extrafont)
font_import(pattern = "Times New Roman")
loadfonts()
## 绘图
library(stringr)
library(dplyr)
library(geomtextpath)
library(ggplot2)
## 加载原始数据集
hike_data <- readr::read_rds(url('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-11-24/hike_data.rds')) ## 如果不能加载数据,就通过链接把 hike_data.rds 下载下来,然后再通过 readr::read_rds() 加载数据
#hike_data <- readr::read_rds("/Users/zhiyuanzhang/Downloads/hike_data.rds")
hike_data$region <- as.factor(word(hike_data$location, 1, sep = " -- "))
## 分组统计 region 的数目
plot_df <- hike_data %>%
group_by(region) %>%
summarise(n = n())
## 新增一列 location,将其转化为 factor,顺序为region数目生序排列
plot_df$location = factor

最低0.47元/天 解锁文章
821

被折叠的 条评论
为什么被折叠?



