绘制
# 加载相关包 library(ggridges) # 山峦图 library(viridis) # 配色 library(extrafont) # 字体 # 导入数据 female_names <- read.csv("female_names.csv") #开始绘制 theme_set(theme_light()) # 主题 plot1 <- ggplot(female_names, aes(year, y=fct_reorder(name, n), height = n/50000, #降低高度以便可视化 group = name)) + geom_ridgeline(alpha=0.5, size = 0,scale = 1.5, # scale缩放山峦高度,1为原比例 fill = "#05595B", color = "white") + xlim(1900,NA) + labs(title = '10 most common given female names\n in the US since 1900', y ="", x="") + theme(plot.title = element_text(hjust = 0, family = "Bahnschrift", size =10), axis.ticks.y = element_blank(), axis.text = element_text(family = "Bahnschrift", size = 7), panel.grid.major.x = element_blank(), panel.grid.minor.x = element_blank(), panel.grid.major.y = element_line(size =0.5), panel.border = element_blank()) + geom_segment(aes(x=1967, xend=1967, y=11.9, yend=10.7), # 相当于画个比例尺 color = "#404040") + geom_segment(aes(x=1967, xend=1964, y=11.9, yend=11.9), color = "#404040") + annotate(geom = "text", x = 1970, y = 11.5, label = "73,982 babies called\n'Mary'in 1921", hjust = "left", size = 3, color = "#404040", family = "Bahnschrift") plot1 #saving ggsave("top_names.png", plot1, height = 4, width = 5, dpi = 300, bg = "white")
top_names
参考
https://github.com/lau-cloud/TidyTuesdaycode/blob/