美文网首页好色之徒
2020-03-17 R-南丁格尔玫瑰图

2020-03-17 R-南丁格尔玫瑰图

作者: iColors | 来源:发表于2020-03-17 09:50 被阅读0次

转载自EasyShu公众号,原创Angus

library(tidyverse)
dat <-
  data.frame(id = 1:26,
             height = c(seq(100, 550, 20),
                        seq(650, 700, 20))) %>%
  mutate(
    label = case_when(
      id <= 13 ~ paste0(height, "例 ", LETTERS[id], "国"),
      id <= 21 ~ paste0(height, "例\n", LETTERS[id], "国"),
      T ~ paste0(LETTERS[id], "国\n", height, "例")
    )
  )
#生成模拟数据,设置不同的标签格式

用ggplot绘图

ggplot(data = dat, aes(x = id, y = height, label = label)) +
geom_col(aes(fill = id), width = 1, size = 0) +
geom_col(aes(y = 40), fill = "white", width = 1, alpha = 0.2, size = 0
  ) +
geom_col(aes(y = 20), fill = "white", width = 1, alpha = 0.2, size = 0 )+
coord_polar() +
theme_void() +
scale_y_continuous(limits = c(-60, 701))+
geom_text(data = . %>% filter(id <= 13), nudge_y = 80, angle = 95 - 180 * c(1:13) / 13, fontface = "bold") +
geom_text(data = . %>% filter(between(id, 14, 21)), nudge_y = -55, nudge_x = -0.1, color = "white", fontface = "bold") +
geom_text(data = . %>% filter(id >= 22), nudge_y = -50, color = "white", angle = 80 - 75 * c(1:5)/5, fontface = "bold")+
scale_fill_gradientn( colors = c("#54778f", "#4EB043", "#E69D2A", "#DD4714", "#A61650"),
    guide = F)
image.png

相关文章

网友评论

    本文标题:2020-03-17 R-南丁格尔玫瑰图

    本文链接:https://www.haomeiwen.com/subject/uhezehtx.html