{"id":272,"date":"2022-01-24T10:29:29","date_gmt":"2022-01-24T02:29:29","guid":{"rendered":"https:\/\/linguopeng.top\/?p=272"},"modified":"2022-01-24T10:29:30","modified_gmt":"2022-01-24T02:29:30","slug":"spiralize%e5%b8%b8%e8%a7%84%e7%9a%84%e7%9f%a9%e5%bd%a2%e5%9b%be%e7%94%bb%e6%88%90%e8%9e%ba%e6%97%8b%e5%bd%a2","status":"publish","type":"post","link":"https:\/\/linguopeng.top\/?p=272","title":{"rendered":"spiralize\u5e38\u89c4\u7684\u77e9\u5f62\u56fe\u753b\u6210\u87ba\u65cb\u5f62"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>library(tidyverse)\n#install.packages(\"spiralize\")\nlibrary(spiralize)\nlibrary(ComplexHeatmap) #devtools::install_github(\"jokergoo\/ComplexHeatmap\")\nlibrary(cowplot)\nlibrary(magick)\n#install.packages(\"tidytuesdayR\")\n#install.packages(\"rcartocolor\")\n\nlibrary(\"rcartocolor\")\nlibrary(tidytuesdayR)\n\ntuesdata &lt;- tidytuesdayR::tt_load('2021-12-07')\nspiders &lt;- tuesdata$spiders\n\nunique(spiders$family)\n\n#check most common family\nspiders %&gt;%\n  group_by(family) %&gt;% \n  summarise(n=n()) %&gt;%\n  arrange(desc(n))\n\n#prep data\nplot_data &lt;- spiders %&gt;% \n  filter(family == \"Agelenidae\") %&gt;%\n  select(year) %&gt;% \n  group_by(year) %&gt;%\n  summarise(n=n()) \nplot_data\n\n#colour function\ncol_fun = circlize::colorRamp2(seq(0,120,by=20), rcartocolor::carto_pal(n=7, name=\"Magenta\"))\n\n#spiral plot\nspiral_initialize(xlim=c(1750, 2022), polar_lines_gp = gpar(col = \"white\", lty = 3))\nspiral_track(ylim=c(0, 120), background_gp = gpar(col = NA, fill = \"grey95\"))\nspiral_bars(plot_data$year, plot_data$n, \n            gp = gpar(fill = col_fun(plot_data$n), col = NA))\n\n#add legend\nlgd = Legend(title = \"Number of publications\", \n             at = c(0, 60, 120),\n             col_fun = col_fun, \n             direction = \"horizontal\", \n             title_gp = gpar(fontsize = 12, fontfamily=\"sans\", col = \"#6c2167\"),\n             labels_gp = gpar(fontsize = 12, fontfamily=\"sans\", col = \"#6c2167\"),\n             legend_width = unit(60, \"mm\"),\n             title_position = \"topcenter\")\ndraw(lgd, x = unit(0.5, \"npc\") , y=unit(-0.1, \"npc\"), \n     just = \"center\") \n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/linguopeng.top\/wp-content\/uploads\/2022\/01\/Rplot-1.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"758\" height=\"830\" data-original=\"https:\/\/linguopeng.top\/wp-content\/uploads\/2022\/01\/Rplot-1.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-274\"\/><\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3],"class_list":["post-272","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-r"],"_links":{"self":[{"href":"https:\/\/linguopeng.top\/index.php?rest_route=\/wp\/v2\/posts\/272","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linguopeng.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linguopeng.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linguopeng.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linguopeng.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=272"}],"version-history":[{"count":2,"href":"https:\/\/linguopeng.top\/index.php?rest_route=\/wp\/v2\/posts\/272\/revisions"}],"predecessor-version":[{"id":275,"href":"https:\/\/linguopeng.top\/index.php?rest_route=\/wp\/v2\/posts\/272\/revisions\/275"}],"wp:attachment":[{"href":"https:\/\/linguopeng.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=272"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linguopeng.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=272"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linguopeng.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=272"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}