这种小清新版箱线图怎么做超简单

2022/8/22 来源:不详

口碑好的白癜风医院 https://wapjbk.39.net/yiyuanfengcai/yyjs_bjzkbdfyy/
?

本节来介绍如何使用「ggplot2」来绘制小清新版箱线图并添加统计信息,下面通过一个小栗子来进行展示

?加载R包

library(tidyverse)library(scales)library(ggtext)导入数据

binded_first-read.delim("data.xls",sep="\t")自定义分面标签

facet_labels-data.frame(test=c("aca","ca","cea","crp"),label=c("CA19-9[U/mL]","CA[U/mL]","CEA[ng/mL]","CRP[mg/mL]"))自定义刻度标签

my_y_labels-c(0,.01,.1,.5,1,5,10,50,,,"1,","10,")数据清洗

stats_data_first-binded_first%%pivot_longer(first_aca:first_crp,names_to="names",values_to="values")%%separate(names,into=c("time","test"),sep="_")%%group_by(test)%%summarise(p_value=round(wilcox.test(values~group)p.value,2))%%mutate(label=if_else(p_value.05,paste0(p_value,"*"),as.character(p_value)),label_asteriks=if_else(p_value==0,"p0.01*",paste0("p=",as.character(label))))

#Atibble:4x4testp_valuelabellabel_asterikschrdblchrchr1aca0..27p=0.ca0..34p=0.cea0..73p=0.crp0..81p=0.81数据可视化

binded_first%%pivot_longer(first_aca:first_crp,names_to="names",values_to="values")%%separate(names,into=c("time","test"),sep="_")%%ggplot(aes(group,values))+stat_boxplot(geom="errorbar",width=.3,size=.7,coef=1)+geom_boxplot(width=.55,outlier.shape=NA,coef=1)+geom_point(position=position_jitter(seed=,width=.25),aes(color=group,shape=group),alpha=.4,size=3)+scale_y_continuous(trans="log10",breaks=c(0,.01,.1,.5,1,5,10,50,,,0,00),limits=c(0.,9),labels=as.character(my_y_labels))+scale_color_manual(values=c("#3B9AB2","#00A08A"))+facet_wrap(~test,nrow=1,strip.position="right")+scale_x_discrete(position="top",labels=c("Controls","iCRS/HIPEC"))+theme_bw()+theme(strip.text=element_blank(),panel.spacing=unit(0,"cm"),axis.title.x=element_blank(),axis.title.y=element_blank(),axis.text.x=element_text(size=12,vjust=1,color="black"),axis.ticks.x.top=element_line(color="black",size=.5),axis.ticks.length=unit(-0.2,"cm"),axis.ticks.y=element_line(color="black",size=.5),axis.text.y=element_text(size=10,color="black"),legend.position="none",panel.grid=element_blank(),plot.margin=unit(c(0.5,0.1,0.5,0.1),"cm"))+geom_rect(xmin=1,xmax=2,ymin=-1.7,ymax=-2.3,color="black",fill="white",size=.5)+geom_text(data=facet_labels,aes(x=1.5,y=.01,label=label),size=4.1)+geom_text(data=stats_data_first,aes(x=1.5,y=,label=label_asteriks),size=5)+geom_segment(aes(x=1,xend=2,y=,yend=),color="black")+geom_segment(aes(x=1,xend=1,y=,yend=3),color="black")+geom_segment(aes(x=2,xend=2,y=,yend=3),color="black")推荐阅读预览时标签不可点收录于话题#个上一篇下一篇

转载请注明:
http://www.3g-city.net/gjyyf/1538.html
  • 上一篇文章:

  • 下一篇文章:
  • 网站首页 版权信息 发布优势 合作伙伴 隐私保护 服务条款 网站地图 网站简介

    温馨提示:本站信息不能作为诊断和医疗依据
    版权所有2014-2024 冀ICP备19027023号-6
    今天是: