Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 15 additions & 24 deletions Hiplot/051-eulerr.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
title: "Eulerr Plot"
author:
- "**[Editor]** [Hu Zheng](https://github.com/ZhengTiger);"
- "**[Contributors]** "
---

::: callout-note
Expand All @@ -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")
}
Expand All @@ -37,8 +30,6 @@ if (!requireNamespace("ggplotify", quietly = TRUE)) {
}

# Load packages
library(data.table)
library(jsonlite)
library(eulerr)
library(ggplotify)
```
Expand All @@ -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
Expand All @@ -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")
)

Expand Down
39 changes: 15 additions & 24 deletions Hiplot/051-eulerr.zh.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
title: "比例韦恩图"
author:
- "**[编辑]** [郑虎](https://github.com/ZhengTiger);"
- "**[审核]** ."
---

::: callout-note
Expand All @@ -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")
}
Expand All @@ -37,8 +30,6 @@ if (!requireNamespace("ggplotify", quietly = TRUE)) {
}

# 加载包
library(data.table)
library(jsonlite)
library(eulerr)
library(ggplotify)
```
Expand All @@ -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)
```

## 可视化
Expand All @@ -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")
)

Expand Down