一归敬、前言
條形圖與柱形圖類似酷含,在柱形圖的基礎(chǔ)上進(jìn)行了橫縱坐標(biāo)變換。條形圖也是最簡單的類別比較型圖(之一)汪茧,學(xué)術(shù)論文中經(jīng)常使用的條形圖主要有2個作用:
- 展示不同類別變量的數(shù)值大幸窝恰;
- 比較不同類別變量之間的大小關(guān)系眨唬。
1.1 單數(shù)據(jù)系列條形圖
1.2 多數(shù)據(jù)系列條形圖
1.3 堆積條形圖
1.4 百分比堆積條形圖
二五辽、R包
本期使用的R包主要有3個糠睡。
tidyverse包是一個集成包珠插,包括
- ggplot2包:用于數(shù)據(jù)可視化惧磺;
- dplyr包:用于數(shù)據(jù)操作;
- tidyr包:用于數(shù)據(jù)整理捻撑;
- readr包:用于數(shù)據(jù)導(dǎo)入磨隘;
- purrr包:用于函數(shù)式編程;
- tibble:用于一種新型數(shù)據(jù)框顾患;
- stringr包:用于字符串琳拭;
- forcats包:用于因子。
# load "gWQS" package
library(gWQS)
# load "dlookr" package
library(dlookr)
# load "tidyverse" package
library(tidyverse)
三描验、演示數(shù)據(jù)
演示數(shù)據(jù)集簡介:gWQS包中有一個內(nèi)置數(shù)據(jù)集白嘁,內(nèi)置數(shù)據(jù)集的名稱叫wqs_data,wqs_data數(shù)據(jù)集有34種多環(huán)芳烴暴露數(shù)據(jù)膘流、25種鄰苯二甲酸酯暴露數(shù)據(jù)和其他類型數(shù)據(jù)絮缅。
本期僅使用wqs_data數(shù)據(jù)集的前5種多環(huán)芳烴暴露數(shù)據(jù)和性別。
# PCBs name
PCBs_name <- c("LBX074LA","LBX099LA","LBX105LA","LBX118LA","LBX138LA")
# get the first 5 PCBs exposure data and sex
PCBs <- wqs_data[c(PCBs_name,"sex")]
# get PCBs' absolute value
PCBs[PCBs_name] <- abs(PCBs[PCBs_name])
# view PCBs data
head(PCBs)
四呼股、R語言實現(xiàn)
4.1 單數(shù)據(jù)系列條形圖
PCBs %>%
# calculate describe statistics
describe(statistics=c("mean","sd")) %>%
# draw bar plot
ggplot() +
# geometry layer
geom_bar(aes(x=reorder(described_variables,mean),y=mean),
stat="identity",
# visual channel mapping
fill="blue")+
# coordinate adjustment
scale_x_discrete(name="PCBs") +
scale_y_continuous(name="Concentration of PCBs in urine (mg/kg)") +
coord_flip() +
# theme adjustment
theme_light()
4.2 多數(shù)據(jù)系列條形圖
PCBs %>%
# group by sex
group_by(sex) %>%
# calculate describe statistics
describe(statistics=c("mean","sd")) %>%
# draw bar plot
ggplot() +
# geometry layer
geom_bar(aes(x=reorder(described_variables,mean),y=mean,fill=sex),
stat="identity",
# visual channel mapping
position="dodge",
width=0.6) +
# coordinate adjustment
scale_x_discrete(name="PCBs") +
scale_y_continuous(name="Concentration of PCBs in urine (mg/kg)") +
coord_flip() +
# legend adjustment
scale_fill_manual(name="Sex",values=c("red","blue"),labels=c("Male","Female")) +
# theme adustment
theme_light() +
theme(legend.position="top")
4.3 堆積條形圖
PCBs %>%
# group by sex
group_by(sex) %>%
# calculate describe statistics
describe(statistics=c("mean","sd")) %>%
# draw bar plot
ggplot() +
# geometry layer
geom_bar(aes(x=reorder(described_variables,mean),y=mean,fill=sex),
stat="identity",
# visual channel mapping
position="stack",
width=0.6) +
# coordinate adjustment
scale_x_discrete(name="PCBs") +
scale_y_continuous(name="Concentration of PCBs in urine (mg/kg)") +
coord_flip() +
# legend adjustment
scale_fill_manual(name="Sex",values=c("red","blue"),labels=c("Male","Female")) +
# theme adustment
theme_light() +
theme(legend.position="top")
4.4 百分比堆積柱形圖
PCBs %>%
# group by sex
group_by(sex) %>%
# calculate describe statistics
describe(statistics=c("mean","sd")) %>%
# draw bar plot
ggplot() +
# geometry layer
geom_bar(aes(x=reorder(described_variables,mean),y=mean,fill=sex),
stat="identity",
# visual channel mapping
position="fill",
width=0.6) +
# coordinate adjustment
scale_x_discrete(name="PCBs") +
scale_y_continuous(name="Concentration of PCBs in urine (mg/kg)") +
coord_flip() +
# legend adjustment
scale_fill_manual(name="Sex",values=c("red","blue"),labels=c("Male","Female")) +
# theme adustment
theme_light() +
theme(legend.position="top")
五耕魄、結(jié)果解讀
NHANES數(shù)據(jù)庫中多環(huán)芳烴的編碼與對應(yīng)名稱。
編碼 | 多環(huán)芳烴 |
---|---|
LBX074LA | PCB74 |
LBX099LA | PCB99 |
LBX105LA | PCB105 |
LBX118LA | PCB118 |
LBX138LA | PCB138 |
- PCB74是人體尿液中含量最高的PCBs彭谁,其次是PCB138吸奴、PCB105和PCB99,PCB118在人體尿液中的含量最低。
- 除了PCB74则奥,女性尿液中PCBs含量一般高于男性考润。
本文由mdnice多平臺發(fā)布