今天来分享一个如何将柱状图转换成圆圈图的小案例,各位观众老爷细细品味,为了方便观看我制作了一个交互式文档用于代码演示,喜欢的小伙伴后台回复关键词2021-4-2获取交互式文档
加载R包
library(tidyverse)
library(ggrepel)
#BiocManager::install("PNWColors")
library(PNWColors)
定义字体
sysfonts::font_add_google("Patua One", "Patua")
sysfonts::font_add_google("Lato", "Lato")
showtext::showtext_auto()
数据可视化
tribble(
~where, ~perc, ~A,
"in the plain", 86, 5,
"not in the plain", 10, 5
) %>%
ggplot(aes(x =A,y=perc,fill = where))+
geom_col()+
geom_text_repel(data = . %>% filter(where == "in the plain"),
aes(label = where, x = 5, y = 90),
nudge_x = 1.5,
nudge_y = -5,
box.padding = 2,
segment.curvature = -0.1,
hjust = 1,
family = "Lato")+
geom_text_repel(data = . %>% filter(where == "not in the plain"),
aes(label = where, x = 5, y = 5),
nudge_x = -1.5,
nudge_y = 0,
box.padding = 1,
segment.curvature = -0.1,
hjust = 1,
family = "Lato")+
coord_polar(theta = "y")+
scale_fill_manual(values = PNWColors::pnw_palette("Bay", 3))+
xlim(0,6)+
labs(title = "Where is the rain in Spain?",
subtitle = "mainly in the plain")+
theme_void()+
theme(legend.position = "none",
panel.background = element_rect(fill = "#F9F8F1",
color = NA),
plot.background = element_rect(fill = "#F9F8F1",
color = NA),
plot.title = element_text(hjust = 0.5,
family = "Patua",face = "bold",size = 25),
plot.subtitle = element_text(hjust = 0.5,
family = "Lato",face = "italic",size = 22),
plot.caption = element_text(hjust = 0.5,
family = "Lato", color = "grey50"))+
NULL
可以看到这是很简单的一个案例,但是通过线条的注释及细节的修改也是很美观的,我们也可以基于此绘制一个基因的热图信息;代码中在几何对象内部对数据过滤,又进一步减少了中间变量的产生
往期精彩:
配置R与Rstudio
ggplot2中的一些关键概念
tidyverse的基础使用
ggplot2绘制终极版热图
ggtree绘制进化树
初探相关性热图
再探相关性热图
ggplot2绘制相关性热图
初探柱状图
绘制具有显著性的条形图
ggplo2绘制经典条形图
ggplo2绘制双误差线条行图
揭开ggplot2中stat图层的神秘面纱
R中的图片注释神包aplot
ggplot2使用patchwork高质量拼图
ggplot2绘制基础散点图
ggplot2绘制经典散点图-1
ggplot2绘制经典散点图-2
ggplot2绘制云雨图
ggplot2绘制经典云雨图
ggplot2绘制哑铃图
ggplot2绘制经典哑铃图
ggplot2添加git

