qqboxplot作为ggplot的扩展,可以实现q-q箱线图的绘制。
BiocManager::install("qqboxplot")library(qqboxplot)
library(ggplot2)
library(dplyr)
#设置统一文本大小
eltext <- 12
#q-q boxplot
qqbox <- expression_data %>%
ggplot(aes(specimen, log_count)) + geom_qqboxplot(varwidth = TRUE, notch = TRUE) +
ylab('logged normalized expression') + ggtitle("c) q-q boxplot") +
theme(plot.title=element_text(size=eltext, face="plain", hjust=0.5), axis.title.x = element_text(size=eltext), axis.title.y = element_text(size=eltext),
panel.border = element_blank(), panel.background = element_rect(fill="white"),
panel.grid.major = element_line(colour = "grey70"),
panel.grid.minor = element_line(colour="grey80"))
#常规箱型图
box <- expression_data %>%
ggplot(aes(specimen, log_count)) + geom_boxplot(varwidth = TRUE, notch = TRUE) +
ylab('logged normalized expression') + ggtitle('a) boxplot') +
theme(plot.title=element_text(size=eltext, face="plain", hjust=0.5), axis.title.x = element_text(size=eltext), axis.title.y = element_text(size=eltext),
panel.border = element_blank(), panel.background = element_rect(fill="white"),
panel.grid.major = element_line(colour = "grey70"),
panel.grid.minor = element_line(colour="grey80"))
override.shape <- c(16, 17)
#q-q plot
qq <- expression_data %>%
ggplot(aes(sample=log_count)) + geom_qq(aes(color=specimen, shape=specimen)) +
xlab('theoretical normal distribution') +
ylab('logged normalized expression') + ggtitle('b) q-q plot') +
labs(color="specimen") +
guides(color = guide_legend(override.aes = list(shape=override.shape)), shape=FALSE) +
theme(plot.title=element_text(size=eltext, face="plain", hjust=0.5), axis.title.x = element_text(size=eltext), axis.title.y = element_text(size=eltext),
panel.border = element_blank(), panel.background = element_rect(fill="white"),
panel.grid.major = element_line(colour = "grey70"),
panel.grid.minor = element_line(colour="grey80"),
legend.position = c(0.8, 0.2))
library(gridExtra)
#合并图片
gridExtra::grid.arrange(box, qq, qqbox, ncol=3)
tibble(y=c(rnorm(1000, mean=2), rt(1000, 16), rt(500, 4), rt(1000, 8), rt(1000, 32)), group=c(rep("normal, mean=2", 1000), rep("t distribution, df=16", 1000), rep("t distribution, df=4", 500), rep("t distribution, df=8", 1000), rep("t distribution, df=32", 1000)))
simulated_data %>% ggplot(aes(factor(group, levels=c("normal, mean=2", "t distribution, df=32", "t distribution, df=16", "t distribution, df=8", "t distribution, df=4")), y=y)) + geom_boxplot(notch=TRUE, varwidth = TRUE) + xlab(NULL) + ylab(NULL) + theme(axis.text.x = element_text(angle = 23, size = 15), axis.title.y = element_text(size=15), panel.border = element_blank(), panel.background = element_rect(fill="white"), panel.grid = element_line(colour = "grey70"))
override.shape <- c(16, 17, 15, 3, 7)
simulated_data %>% ggplot(aes(sample=y, color=factor(group, levels=c("normal, mean=2", "t distribution, df=32", "t distribution, df=16", "t distribution, df=8", "t distribution, df=4")),
shape=factor(group, levels=c("normal, mean=2", "t distribution, df=32", "t distribution, df=16", "t distribution, df=8", "t distribution, df=4")))) +
geom_qq() + geom_qq_line() + labs(color="distribution") +
xlab("Normal Distribution") +
ylab("Simulated Datasets") +
guides(color = guide_legend(override.aes = list(shape=override.shape)), shape=FALSE) +
theme(axis.title.x = element_text(size=15), axis.title.y = element_text(size=15),
panel.border = element_blank(), panel.background = element_rect(fill="white"),
panel.grid = element_line(colour = "grey70"))
simulated_data %>% ggplot(aes(factor(group, levels=c("normal, mean=2", "t distribution, df=32", "t distribution, df=16", "t distribution, df=8", "t distribution, df=4")), y=y)) + geom_qqboxplot(notch=TRUE, varwidth = TRUE, reference_dist="norm") + xlab("reference: normal distribution") + ylab(NULL) + guides(color=FALSE) + theme(axis.text.x = element_text(angle = 23, size = 15), axis.title.y = element_text(size=15), axis.title.x = element_text(size=15), panel.border = element_blank(), panel.background = element_rect(fill="white"), panel.grid = element_line(colour = "grey70"))
comparison_data <- indicators %>% filter(year==2008 & `Series Code`=="SL.TLF.ACTI.1524.MA.NE.ZS")
indicators %>%
#将series名称中的标签更改为较短的标题
mutate(`Series Name`= ifelse(
`Series Name`=="Labor force participation rate for ages 15-24, male (%) (national estimate)",
"Male ages 15-24",
"Female ages 15-24")) %>%
ggplot(aes(as.factor(year), y=indicator))+
geom_qqboxplot(notch=TRUE, varwidth = TRUE, compdata=comparison_data$indicator) +
xlab("Year") +
ylab("Country level labor force\nparticipation rate (%)") +
facet_wrap(~factor(`Series Name`, levels = c("Male ages 15-24", "Female ages 15-24"))) +
theme(strip.text = element_text(size=12), axis.text.x = element_text(size = 15), axis.title.x = element_text(size=15),
axis.title.y = element_text(size=12),
panel.border = element_blank(), panel.background = element_rect(fill="white"),
panel.grid = element_line(colour = "grey70"))
spike_data %>% filter(region=="V1") %>% ggplot(aes(factor(orientation), nspikes)) + geom_qqboxplot(notch=TRUE, varwidth = TRUE, reference_dist="norm") + xlab("orientation") + ylab("spike count") + theme(axis.text.x = element_text(size = 15), axis.text.y = element_text(size=14), axis.title.x = element_text(size=15), axis.title.y = element_text(size=15), panel.border = element_blank(), panel.background = element_rect(fill="white"), panel.grid = element_line(colour = "grey70"))
同样的数据用bean plot展示
spike_data %>% filter(region=="V1") %>% ggplot()+ geom_violin(aes(x=factor(orientation),y=nspikes),fill='grey',trim=F, draw_quantiles = c(.25, .5, .75))+ geom_segment(aes( x=match(factor(orientation),levels(factor(orientation)))-0.1, xend=match(factor(orientation),levels(factor(orientation)))+0.1, y=nspikes,yend=nspikes), col='black' ) + xlab("orientation") + ylab("spike count") + theme(axis.text.x = element_text(size = 15), axis.text.y = element_text(size=14), axis.title.x = element_text(size=15), axis.title.y = element_text(size=15), panel.border = element_blank(), panel.background = element_rect(fill="white"), panel.grid = element_line(colour = "grey70"))
不感兴趣
看过了
取消
人点赞
人收藏
打赏
不感兴趣
看过了
取消
打赏金额
认可我就打赏我~
1元 5元 10元 20元 50元 其它打赏作者
认可我就打赏我~
扫描二维码
立即打赏给Ta吧!
温馨提示:仅支持微信支付!