当前位置:网站首页>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 11:50:00 【Xiaoyu 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"
)
边栏推荐
- b格高且好看的代码片段分享图片生成
- How to Visualize Missing Data in R using a Heatmap
- Compilation errors and printout garbled problems caused by Chinese content in vs2019 code
- Principe du contrat évolutif - delegatecall
- Power Spectral Density Estimates Using FFT---MATLAB
- ROS lacks xacro package
- MySQL stored procedure cursor traversal result set
- GGHIGHLIGHT: EASY WAY TO HIGHLIGHT A GGPLOT IN R
- Attribute acquisition method and operation notes of C # multidimensional array
- Principle of scalable contract delegatecall
猜你喜欢

ESP32存储配网信息+LED显示配网状态+按键清除配网信息(附源码)

Map set assignment to database

Power Spectral Density Estimates Using FFT---MATLAB

R HISTOGRAM EXAMPLE QUICK REFERENCE

Webauthn - official development document

电脑无缘无故黑屏,无法调节亮度。

2022年遭“挤爆”的三款透明LED显示屏

How to Add P-Values onto Horizontal GGPLOTS

Power Spectral Density Estimates Using FFT---MATLAB

Tiktok overseas tiktok: finalizing the final data security agreement with Biden government
随机推荐
A sharp tool for exposing data inconsistencies -- a real-time verification system
MySQL linked list data storage query sorting problem
基于Hardhat和Openzeppelin开发可升级合约(一)
Tidb DM alarm DM_ sync_ process_ exists_ with_ Error troubleshooting
What is the relationship between digital transformation of manufacturing industry and lean production
The selected cells in Excel form have the selection effect of cross shading
Mmrotate rotation target detection framework usage record
The computer screen is black for no reason, and the brightness cannot be adjusted.
Bedtools tutorial
ROS lacks xacro package
2022年遭“挤爆”的三款透明LED显示屏
How to Create a Nice Box and Whisker Plot in R
Redis超出最大内存错误OOM command not allowed when used memory &gt; 'maxmemory'
亚马逊云科技 Community Builder 申请窗口开启
基于 Openzeppelin 的可升级合约解决方案的注意事项
Pyqt5+opencv project practice: microcirculator pictures, video recording and manual comparison software (with source code)
制造业数字化转型和精益生产什么关系
Power Spectral Density Estimates Using FFT---MATLAB
Webauthn - official development document
Wechat applet uses Baidu API to achieve plant recognition
