library(tidyverse)
#install.packages("spiralize")
library(spiralize)
library(ComplexHeatmap) #devtools::install_github("jokergoo/ComplexHeatmap")
library(cowplot)
library(magick)
#install.packages("tidytuesdayR")
#install.packages("rcartocolor")
library("rcartocolor")
library(tidytuesdayR)
tuesdata <- tidytuesdayR::tt_load('2021-12-07')
spiders <- tuesdata$spiders
unique(spiders$family)
#check most common family
spiders %>%
group_by(family) %>%
summarise(n=n()) %>%
arrange(desc(n))
#prep data
plot_data <- spiders %>%
filter(family == "Agelenidae") %>%
select(year) %>%
group_by(year) %>%
summarise(n=n())
plot_data
#colour function
col_fun = circlize::colorRamp2(seq(0,120,by=20), rcartocolor::carto_pal(n=7, name="Magenta"))
#spiral plot
spiral_initialize(xlim=c(1750, 2022), polar_lines_gp = gpar(col = "white", lty = 3))
spiral_track(ylim=c(0, 120), background_gp = gpar(col = NA, fill = "grey95"))
spiral_bars(plot_data$year, plot_data$n,
gp = gpar(fill = col_fun(plot_data$n), col = NA))
#add legend
lgd = Legend(title = "Number of publications",
at = c(0, 60, 120),
col_fun = col_fun,
direction = "horizontal",
title_gp = gpar(fontsize = 12, fontfamily="sans", col = "#6c2167"),
labels_gp = gpar(fontsize = 12, fontfamily="sans", col = "#6c2167"),
legend_width = unit(60, "mm"),
title_position = "topcenter")
draw(lgd, x = unit(0.5, "npc") , y=unit(-0.1, "npc"),
just = "center")
暂无评论