画图生信绘图R可视化小本本

【R>>ggforce】给Cluster画个小圈圈

2021-05-31  本文已影响0人  高大石头

用ggplot2画图时,常常需要给不同的cluster加上圆圈或椭圆,这时候ggforce就派上用上了。 核心函数:

核心图:


下面以palmerpenguins数据集为例。

示例数据

rm(list = ls())
library(palmerpenguins)
library(ggforce)
penguins <- penguins %>% 
  drop_na()
penguins %>% 
  head(3)
## # A tibble: 3 x 8
##   species island bill_length_mm bill_depth_mm flipper_length_~ body_mass_g sex  
##   <fct>   <fct>           <dbl>         <dbl>            <int>       <int> <fct>
## 1 Adelie  Torge~           39.1          18.7              181        3750 male 
## 2 Adelie  Torge~           39.5          17.4              186        3800 fema~
## 3 Adelie  Torge~           40.3          18                195        3250 fema~
## # ... with 1 more variable: year <int>
penguins %>% 
  ggplot(aes(bill_length_mm,flipper_length_mm,color=species))+
  geom_point()

加上圆圈圈

penguins %>% 
  ggplot(aes(bill_length_mm,flipper_length_mm,color=species))+
  geom_point()+
  geom_mark_circle(aes(color=species),
                       expand=unit(0.5,"mm"))

椭圆

penguins %>% 
  ggplot(aes(bill_length_mm,flipper_length_mm,color=species))+
  geom_point()+
  geom_mark_ellipse(aes(color=species,
                        label=species),
                    expand = unit(0.5,"mm"),
                    label.buffer = unit(-5,"mm"))+
  theme(legend.position = "none")
penguins %>% 
  ggplot(aes(bill_length_mm,flipper_length_mm))+
  geom_point(aes(color=species))+
  geom_mark_ellipse(aes(fill=species,
                        label=species),
                    expand = unit(0.5,"mm"),
                    label.buffer = unit(-5,"mm"))+
  theme(legend.position = "none")

从上面可以看出画出来的圈圈和椭圆效果还是可以的,用到你的SCI论文中去吧。

参考链接:

How to Annotate a Plot with Circle in R

上一篇 下一篇

猜你喜欢

热点阅读