当前位置:网站首页>How to Create a Beautiful Plots in R with Summary Statistics Labels
How to Create a Beautiful Plots in R with Summary Statistics Labels
2022-07-02 09:38:00 【小宇2022】
library(tidyverse)
library(rstatix)
library(ggpubr)
# Demo data
data("ToothGrowth")
df <- ToothGrowth
df$dose <- as.factor(df$dose)
# Add random QC column
set.seed(123)
qc <- rep(c("pass", "fail"), 30)
df$qc <- as.factor(sample(qc, 60))
# Inspect the data
head(df)
# Basic plot
ggsummarystats(
df, x = "dose", y = "len",
ggfunc = ggboxplot, add = "jitter"
)

library(tidyverse)
library(rstatix)
library(ggpubr)
# Demo data
data("ToothGrowth")
df <- ToothGrowth
df$dose <- as.factor(df$dose)
# Add random QC column
set.seed(123)
qc <- rep(c("pass", "fail"), 30)
df$qc <- as.factor(sample(qc, 60))
# Inspect the data
head(df)
# Color by groups
ggsummarystats(
df, x = "dose", y = "len",
ggfunc = ggboxplot, add = "jitter",
color = "dose", palette = "npg"
)

# Grouped plots
ggsummarystats(
df, x = "dose", y = "len",
ggfunc = ggboxplot, add = "jitter",
color = "supp", palette = "npg"
)
# Change plot type to violin
ggsummarystats(
df, x = "dose", y = "len",
ggfunc = ggviolin, add = c("jitter", "median_iqr"),
color = "supp", palette = "npg"
)

library(tidyverse)
library(rstatix)
library(ggpubr)
# Demo data
data("ToothGrowth")
df <- ToothGrowth
df$dose <- as.factor(df$dose)
# Add random QC column
set.seed(123)
qc <- rep(c("pass", "fail"), 30)
df$qc <- as.factor(sample(qc, 60))
# Inspect the data
head(df)
# Compute summary statistics
summary.stats <- df %>%
group_by(dose) %>%
get_summary_stats() %>%
select(dose, n, median, iqr)
summary.stats
# Create a boxplot
bxp <- ggboxplot(
df, x = "dose", y = "len", add = "jitter",
ggtheme = theme_bw()
)
# Visualize the summary statistics
summary.plot <- ggsummarytable(
summary.stats, x = "dose", y = c("n", "median", "iqr"),
ggtheme = theme_bw()
) +
clean_table_theme()
# Combine the boxplot and the summary statistics plot
ggarrange(
bxp, summary.plot, ncol = 1, align = "v",
heights = c(0.80, 0.20)
)
# Create barplot
ggsummarystats(
df, x = "dose", y = "len",
ggfunc = ggbarplot, add = c("jitter", "median_iqr"), position = position_dodge(),
color = "supp", palette = "npg"
)

library(tidyverse)
library(rstatix)
library(ggpubr)
# Demo data
data("ToothGrowth")
df <- ToothGrowth
df$dose <- as.factor(df$dose)
# Add random QC column
set.seed(123)
qc <- rep(c("pass", "fail"), 30)
df$qc <- as.factor(sample(qc, 60))
# Inspect the data
head(df)
# Create line plots
ggsummarystats(
df, x = "dose", y = "len",
ggfunc = ggline, add = c("jitter", "median_iqr"),
color = "supp", palette = "npg"
)
边栏推荐
- webauthn——官方开发文档
- STM32 single chip microcomputer programming learning
- Always report errors when connecting to MySQL database
- 三.芯片啟動和時鐘系統
- spritejs
- 从ros1到ros2配置的一些东西
- Homer预测motif
- Redis exceeds the maximum memory error oom command not allowed when used memory & gt; ' maxmemory'
- Gaode draws lines according to the track
- What is the relationship between digital transformation of manufacturing industry and lean production
猜你喜欢

在连接mysql数据库的时候一直报错

map集合赋值到数据库

Wechat applet uses Baidu API to achieve plant recognition

CTF record

Pit of the start attribute of enumrate

【IDEA】使用插件一键逆向生成代码

八大排序汇总

A white hole formed by antineutrons produced by particle accelerators

On April 17, 2022, the five heart matchmaker team received double good news

mmrotate旋转目标检测框架使用记录
随机推荐
Principle of scalable contract delegatecall
Jinshanyun - 2023 Summer Internship
Importerror: impossible d'importer le nom « graph» de « graphviz»
Skills of PLC recorder in quickly monitoring multiple PLC bits
数字化转型挂帅复产复工,线上线下全融合重建商业逻辑
基于 Openzeppelin 的可升级合约解决方案的注意事项
Precautions for scalable contract solution based on openzeppelin
Complement (Mathematical Simulation
JS -- take a number randomly from the array every call, and it cannot be the same as the last time
TIPC protocol
ros gazebo相关包的安装
在网上开股票账户安全吗?我是新手,还请指导
mysql链表数据存储查询排序问题
PHP tea sales and shopping online store
A white hole formed by antineutrons produced by particle accelerators
程序员成长第六篇:如何选择公司?
Thanos Receiver
【云原生】2.5 Kubernetes 核心实战(下)
String (Analog
C#多维数组的属性获取方法及操作注意
