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

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

  • geom_mark_circle(aes(color=species))

  • geom_mark_ellipse(aes(color=species,fill=species,label=species))

核心图:


下面以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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 用到的组件 1、通过CocoaPods安装 2、第三方类库安装 3、第三方服务 友盟社会化分享组件 友盟用户反馈 ...
    SunnyLeong阅读 14,949评论 1 180
  • 我是黑夜里大雨纷飞的人啊 1 “又到一年六月,有人笑有人哭,有人欢乐有人忧愁,有人惊喜有人失落,有的觉得收获满满有...
    陌忘宇阅读 12,732评论 28 53
  • 信任包括信任自己和信任他人 很多时候,很多事情,失败、遗憾、错过,源于不自信,不信任他人 觉得自己做不成,别人做不...
    吴氵晃阅读 11,351评论 4 8
  • 步骤:发微博01-导航栏内容 -> 发微博02-自定义TextView -> 发微博03-完善TextView和...
    dibadalu阅读 8,362评论 1 3
  • 回这一趟老家,心里多了两个疙瘩。第一是堂姐现在谈了一个有妇之夫,在她的语言中感觉,她不打算跟他有太长远的计划,这让...
    安九阅读 8,889评论 2 4