diff --git a/Hiplot/051-eulerr.qmd b/Hiplot/051-eulerr.qmd index 2fb6f93fa..9c5f0d25f 100644 --- a/Hiplot/051-eulerr.qmd +++ b/Hiplot/051-eulerr.qmd @@ -2,7 +2,6 @@ title: "Eulerr Plot" author: - "**[Editor]** [Hu Zheng](https://github.com/ZhengTiger);" - - "**[Contributors]** " --- ::: callout-note @@ -19,16 +18,10 @@ This page is the tutorial for source code version of the Hiplot `Eulerr Plot` pl - Programming language: R -- Dependent packages: `data.table`; `jsonlite`; `eulerr`; `ggplotify` +- Dependent packages: `eulerr`; `ggplotify` ```{r packages setup, message=FALSE, warning=FALSE, output=FALSE} # Install packages -if (!requireNamespace("data.table", quietly = TRUE)) { - install.packages("data.table") -} -if (!requireNamespace("jsonlite", quietly = TRUE)) { - install.packages("jsonlite") -} if (!requireNamespace("eulerr", quietly = TRUE)) { install.packages("eulerr") } @@ -37,8 +30,6 @@ if (!requireNamespace("ggplotify", quietly = TRUE)) { } # Load packages -library(data.table) -library(jsonlite) library(eulerr) library(ggplotify) ``` @@ -50,17 +41,16 @@ sessioninfo::session_info("attached") ## Data Preparation ```{r load data, message=FALSE, warning=FALSE} -# Load data -data <- data.table::fread(jsonlite::read_json("https://hiplot.cn/ui/basic/eulerr/data.json")$exampleData$textarea[[1]]) -data <- as.data.frame(data) - -# convert data structure -genes <- as.numeric(data[, 2]) -names(genes) <- as.character(data[, 1]) +# Self-contained example: synthetic gene counts for three cancer types +genes <- c( + "LUAD" = 1000, "BRCA" = 1200, "COAD" = 800, + "LUAD&BRCA" = 200, "LUAD&COAD" = 150, "BRCA&COAD" = 180, + "LUAD&BRCA&COAD" = 80 +) euler_set <- euler(genes) - + # View data -head(data) +print(genes) ``` ## Visualization @@ -75,15 +65,16 @@ head(data) #| message: false # Eulerr Plot -fill <- c("#3B4992FF","#EE0000FF","#008B45FF","#631879FF","#008280FF","#BB0021FF", - "#5F559BFF","#A20056FF") +fill_colors <- c("#3B4992FF", "#EE0000FF", "#008B45FF", "#631879FF", + "#008280FF", "#BB0021FF", "#5F559BFF", "#A20056FF") n_sets <- length(euler_set$sets) +n_subsets <- length(euler_set$original.values) p <- as.ggplot( plot(euler_set, - labels = list(col = rep("white", length(genes))), - fills = list(fill = fill[seq_len(n_sets)]), + labels = list(col = rep("white", n_sets)), + fills = list(fill = rep_len(fill_colors, n_sets)), quantities = list(type = c("percent", "counts"), - col = rep("white", length(genes))), + col = rep("white", n_subsets)), main = "Eulerr") ) diff --git a/Hiplot/051-eulerr.zh.qmd b/Hiplot/051-eulerr.zh.qmd index 43ad18652..20bce86c3 100644 --- a/Hiplot/051-eulerr.zh.qmd +++ b/Hiplot/051-eulerr.zh.qmd @@ -2,7 +2,6 @@ title: "比例韦恩图" author: - "**[编辑]** [郑虎](https://github.com/ZhengTiger);" - - "**[审核]** ." --- ::: callout-note @@ -19,16 +18,10 @@ author: - 编程语言: R -- 依赖包: `data.table`; `jsonlite`; `eulerr`; `ggplotify` +- 依赖包: `eulerr`; `ggplotify` ```{r packages setup, message=FALSE, warning=FALSE, output=FALSE} # 安装包 -if (!requireNamespace("data.table", quietly = TRUE)) { - install.packages("data.table") -} -if (!requireNamespace("jsonlite", quietly = TRUE)) { - install.packages("jsonlite") -} if (!requireNamespace("eulerr", quietly = TRUE)) { install.packages("eulerr") } @@ -37,8 +30,6 @@ if (!requireNamespace("ggplotify", quietly = TRUE)) { } # 加载包 -library(data.table) -library(jsonlite) library(eulerr) library(ggplotify) ``` @@ -50,17 +41,16 @@ sessioninfo::session_info("attached") ## 数据准备 ```{r load data, message=FALSE, warning=FALSE} -# 加载数据 -data <- data.table::fread(jsonlite::read_json("https://hiplot.cn/ui/basic/eulerr/data.json")$exampleData$textarea[[1]]) -data <- as.data.frame(data) - -# 整理数据格式 -genes <- as.numeric(data[, 2]) -names(genes) <- as.character(data[, 1]) +# 自包含示例:三种癌症类型的模拟基因数目 +genes <- c( + "LUAD" = 1000, "BRCA" = 1200, "COAD" = 800, + "LUAD&BRCA" = 200, "LUAD&COAD" = 150, "BRCA&COAD" = 180, + "LUAD&BRCA&COAD" = 80 +) euler_set <- euler(genes) - + # 查看数据 -head(data) +print(genes) ``` ## 可视化 @@ -75,15 +65,16 @@ head(data) #| message: false # 比例韦恩图 -fill <- c("#3B4992FF","#EE0000FF","#008B45FF","#631879FF","#008280FF","#BB0021FF", - "#5F559BFF","#A20056FF") +fill_colors <- c("#3B4992FF", "#EE0000FF", "#008B45FF", "#631879FF", + "#008280FF", "#BB0021FF", "#5F559BFF", "#A20056FF") n_sets <- length(euler_set$sets) +n_subsets <- length(euler_set$original.values) p <- as.ggplot( plot(euler_set, - labels = list(col = rep("white", length(genes))), - fills = list(fill = fill[seq_len(n_sets)]), + labels = list(col = rep("white", n_sets)), + fills = list(fill = rep_len(fill_colors, n_sets)), quantities = list(type = c("percent", "counts"), - col = rep("white", length(genes))), + col = rep("white", n_subsets)), main = "Eulerr") )