查看原文
其他

ggpie 解决你的所有饼图绘制

JunJunLab 老俊俊的生信笔记 2023-06-15


迷茫在所难免

1前言

scRNAtoolVis 里 1 增加一个新的功能, markerVocalno 绘制 marker 基因的火山图:

test <- system.file("extdata""pbmc.markers.csv", package = "scRNAtoolVis")
markers <- read.csv(test)

# plot
markerVocalno(markers = markers,
              topn = 5,
              labelCol = ggsci::pal_npg()(9))

2引言

今天分享一个比较综合性绘制饼图的 R 包 ggpie,主要包括以下几个函数:

  • ggpie: Create 2D pie plot with single group variable.
  • ggdonut: Create 2D donut plot with single group variable.
  • ggnestedpie: Create 2D nested pie plot with two group variables.
  • ggpie3D: Create 3D pie plot with single group variable.
  • ggrosepie: Create rose pie plot with single or two group variables.

使用文档:

https://cran.r-project.org/web/packages/ggpie/vignettes/ggpie.html

3安装

install.packages("ggpie")

# install.package("remotes")   #In case you have not installed it.
remotes::install_github("showteeth/ggpie")

4使用

加载测试数据

library(ggpie)
library(ggplot2)
data(diamonds)
# check data used
str(diamonds)
#> tibble[,10] [53,940 × 10] (S3: tbl_df/tbl/data.frame)
#>  $ carat  : num [1:53940] 0.23 0.21 0.23 0.29 0.31 0.24 0.24 0.26 0.22 0.23 ...
#>  $ cut    : Ord.factor w/ 5 levels "Fair"<"Good"<..: 5 4 2 4 2 3 3 3 1 3 ...
#>  $ color  : Ord.factor w/ 7 levels "D"<"E"<"F"<"G"<..: 2 2 2 6 7 7 6 5 2 5 ...
#>  $ clarity: Ord.factor w/ 8 levels "I1"<"SI2"<"SI1"<..: 2 3 5 4 2 6 7 3 4 5 ...
#>  $ depth  : num [1:53940] 61.5 59.8 56.9 62.4 63.3 62.8 62.3 61.9 65.1 59.4 ...
#>  $ table  : num [1:53940] 55 61 65 58 58 57 57 55 61 61 ...
#>  $ price  : int [1:53940] 326 326 327 334 335 336 336 337 337 338 ...
#>  $ x      : num [1:53940] 3.95 3.89 4.05 4.2 4.34 3.94 3.95 4.07 3.87 4 ...
#>  $ y      : num [1:53940] 3.98 3.84 4.07 4.23 4.35 3.96 3.98 4.11 3.78 4.05 ...
#>  $ z      : num [1:53940] 2.43 2.31 2.31 2.63 2.75 2.48 2.47 2.53 2.49 2.39 ...

Pie plot

# with no label
ggpie(data = diamonds, group_key = "cut", count_type = "full",label_type = "none")

添加标签:

ggpie(data = diamonds, group_key = "cut", count_type = "full",
      label_info = "all", label_type = "circle",
      label_size = 4, label_pos = "out")

改变标签位置:

ggpie(data = diamonds, group_key = "cut", count_type = "full",
      label_info = "all", label_type = "circle", label_split = NULL,
      label_size = 4, label_pos = "in")

标签水平:

ggpie(data = diamonds, group_key = "cut", count_type = "full",
      label_info = "all", label_type = "horizon", label_split = NULL,
      label_size = 4, label_pos = "in")

标签换行:

ggpie(data = diamonds, group_key = "cut", count_type = "full",
      label_info = "all", label_type = "horizon",
      label_size = 4, label_pos = "in")

添加连接线:

ggpie(data = diamonds, group_key = "cut", count_type = "full",
      label_info = "all", label_type = "horizon",
      label_size = 4, label_pos = "out" )

调整标签与连接线的关系:

ggpie(data = diamonds, group_key = "cut", count_type = "full",
      label_info = "all", label_type = "horizon", label_split = NULL,
      label_size = 4, label_pos = "in", labal_threshold = 10)

Donut plot

# with no label
ggdonut(data = diamonds, group_key = "cut", count_type = "full",label_type = "none")

添加标签:

ggdonut(data = diamonds, group_key = "cut", count_type = "full",
        label_info = "all", label_type = "circle",
        label_size = 4, label_pos = "out")

标签置放里面:

ggdonut(data = diamonds, group_key = "cut", count_type = "full",
        label_info = "all", label_type = "circle", label_split = NULL,
        label_size = 4, label_pos = "in")

标签水平:

ggdonut(data = diamonds, group_key = "cut", count_type = "full",
        label_info = "all", label_type = "horizon", label_split = NULL,
        label_size = 4, label_pos = "in")

标签换行:

ggdonut(data = diamonds, group_key = "cut", count_type = "full",
        label_info = "all", label_type = "horizon",
        label_size = 4, label_pos = "in")

添加连接线:

ggdonut(data = diamonds, group_key = "cut", count_type = "full",
        label_info = "all", label_type = "horizon", label_split = NULL,
        label_size = 4, label_pos = "out")

标签换行:

ggdonut(data = diamonds, group_key = "cut", count_type = "full",
        label_info = "all", label_type = "horizon",
        label_size = 4, label_pos = "out")

调整标签与连接线:

ggdonut(data = diamonds, group_key = "cut", count_type = "full",
        label_info = "all", label_type = "horizon",
        label_size = 4, label_pos = "in", labal_threshold = 10)

3D pie plot

p1= ggpie3D(data = diamonds, group_key = "cut", count_type = "full", tilt_degrees = -10, label_size=2) +
  ggtitle("tilt_degrees = -10") +
  theme(plot.title = element_text(hjust = 0.5))

p2= ggpie3D(data = diamonds, group_key = "cut", count_type = "full", tilt_degrees = -40, label_size=2) +
  ggtitle("tilt_degrees = -40") +
  theme(plot.title = element_text(hjust = 0.5))

p3= ggpie3D(data = diamonds, group_key = "cut", count_type = "full", tilt_degrees = -10,
            start_degrees = 60, label_size=2) +
  ggtitle("start_degrees = 60") +
  theme(plot.title = element_text(hjust = 0.5))

p4= ggpie3D(data = diamonds, group_key = "cut", count_type = "full", tilt_degrees = -10,
            start_degrees = 180, label_size=2) +
  ggtitle("start_degrees = 180") +
  theme(plot.title = element_text(hjust = 0.5))

cowplot::plot_grid(p1,p2,p3,p4,ncol = 2)

Nested pie/donut plot

ggnestedpie(data = diamonds, group_key = c("cut""color"), count_type = "full",
            inner_label_info = "all", inner_label_split = NULL,inner_label_size = 2,
            outer_label_type = "circle", outer_label_pos = "in", outer_label_info = "all")
#> Coordinate system already present. Adding new coordinate system, which will replace the existing one.

去除一些标签:

ggnestedpie(data = diamonds, group_key = c("cut""color"), count_type = "full",
            inner_label_info = "all", inner_label_split = NULL,
            inner_labal_threshold = 5, inner_label_size = 2,
            outer_label_type = "circle", outer_label_pos = "in", outer_label_info = "all")
#> Coordinate system already present. Adding new coordinate system, which will replace the existing one.

标签显示在外层:

ggnestedpie(data = diamonds, group_key = c("cut""color"), count_type = "full",
            inner_label_info = "all", inner_label_split = NULL, inner_label_size = 2,
            outer_label_type = "circle", outer_label_pos = "out", outer_label_info = "all")
#> Coordinate system already present. Adding new coordinate system, which will replace the existing one.

添加连接线:

ggnestedpie(data = diamonds, group_key = c("cut""color"), count_type = "full",
            inner_label_info = "all", inner_label_split = NULL,
            inner_labal_threshold = 1, inner_label_size = 2,
            outer_label_type = "horizon", outer_label_pos = "out", outer_label_info = "all")

调整标签与连接线:

ggnestedpie(data = diamonds, group_key = c("cut""color"), count_type = "full",
            inner_label_info = "all", inner_label_split = NULL,
            inner_labal_threshold = 1, inner_label_size = 2,
            outer_label_type = "horizon", outer_label_pos = "in",
            outer_label_info = "all", outer_labal_threshold = 10)

嵌套饼图间添加空隙:

ggnestedpie(data = diamonds, group_key = c("cut""color"), count_type = "full",
            r0 = 0.5, r1 = 1.5, r2 = 2.6,inner_label_info = "all", inner_label_split = NULL,
            inner_labal_threshold = 1, inner_label_size = 2,
            outer_label_type = "horizon", outer_label_pos = "in",
            outer_label_info = "all", outer_labal_threshold = 10)

Rose pie/donut plot

# pie plot
p1=ggrosepie(diamonds, group_key = "color", count_type = "full", label_info = "all",
             show_tick=F,donut_frac=NULL)
# donut plot
p2=ggrosepie(diamonds, group_key = "color", count_type = "full", label_info = "all",
             show_tick=F,donut_frac=0.3,donut_label_size=3)
cowplot::plot_grid(p1,p2)

添加刻度:

# pie plot
p1=ggrosepie(diamonds, group_key = "color", count_type = "full", label_info = "all",
             donut_frac=NULL)
# donut plot
p2=ggrosepie(diamonds, group_key = "color", count_type = "full", label_info = "all",
             donut_frac=0.3,donut_label_size=3)
cowplot::plot_grid(p1,p2)

添加指定刻度:

# pie plot
p1=ggrosepie(diamonds, group_key = "color", count_type = "full", label_info = "all",
             tick_break = c(3000,5000,7000,11000), donut_frac=NULL)
# donut plot
p2=ggrosepie(diamonds, group_key = "color", count_type = "full", label_info = "all",
             tick_break = c(3000,5000,7000,11000), donut_frac=0.3,donut_label_size=3)
cowplot::plot_grid(p1,p2)

两个变量:

# pie plot
p1=ggrosepie(diamonds, group_key = c("color","clarity"),
             count_type = "full", label_info = "all",
             show_tick=F,donut_frac=NULL)
# donut plot
p2=ggrosepie(diamonds, group_key = c("color","clarity"),
             count_type = "full", label_info = "all",
             show_tick=F,donut_frac=0.3,donut_label_size=3)
cowplot::plot_grid(p1,p2)

添加刻度:

# pie plot
p1=ggrosepie(diamonds, group_key = c("color","clarity"),
             count_type = "full", label_info = "all",
             donut_frac=NULL)
# donut plot
p2=ggrosepie(diamonds, group_key = c("color","clarity"),
             count_type = "full", label_info = "all",
             donut_frac=0.3,donut_label_size=3)
cowplot::plot_grid(p1,p2)

5结尾

总之功能还是非常的齐全,大家赶快去使用吧。




  老俊俊生信交流群 (微信交流群需收取20元入群费用(防止骗子和便于管理))


老俊俊微信:


知识星球:



今天的分享就到这里了,敬请期待下一篇!

最后欢迎大家分享转发,您的点赞是对我的鼓励肯定

如果觉得对您帮助很大,赏杯快乐水喝喝吧!



  





Bigwig 可视化用 tackPlotR 试试看?

gggsea 个性化绘制 GSEA 图

scRNAtoolVis 绘制单细胞 Marker 基因均值表达热图

给你 UMAP 坐标重复文章一模一样的图?

genesorteR 快速准确鉴定亚群 Marker 基因

scRNAtoolVis 尝试一下?

Seurat 官网单细胞教程四 (细胞周期矫正)

跟着 Nature medicine 学单细胞数据分析

单细胞亚群分面可视化

跟着 Nature medicine 学画图-tSNE

◀...

您可能也对以下帖子感兴趣

文章有问题?点此查看未经处理的缓存