为了将显示相关系数与方程式的两个文本对齐,上图为左对齐,需设置stat_cor()和stat_poly_eq()中label.x的值相同(横轴位置相同), 设置label.y来控制两文本的间隔。同时,需要设置stat_poly_eq()中geom = “text”。此外,在指定的(label.x, label.y)位置处显示文本,stat_cor()默认为左对齐,而stat_poly_eq(...
在R语言的绘图过程中,当需要在点图与拟合曲线旁边展示相关系数和显著性水平时,ggpubr包中的stat_cor函数提供了便捷的解决方案。首先,通过计算相关系数,我们可以调用ggpubr的相应函数轻松将其添加到图表中。例如,对于科学计数的P值,可以通过适当设置转换为更为直观的计数形式。当数据带有分组变量时,...
增加相关系数和P值的有效数位: b+geom_point(aes(color=cyl))+geom_smooth(aes(color=cyl),method=lm,se=FALSE,fullrange=TRUE)+scale_color_manual(values=c("#00AFBB","#E7B800","#FC4E07"))+ggpubr::stat_cor(aes(color=cyl),method='pearson',label.x=2.4,r.digits=3,p.digits=4) image....
stat_cor(label.x=35000,label.y=3,size=2.5)+ # 相关系数的位置坐标 theme_bw()+ # 设置图形主题 theme(legend.position="none") # 去掉图例 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. #图19 按上市板块分类的带有边际箱线图与核密度图的散点图 data5_1<-read.csv("./mydata/chap05/dat...
stat_cor(method = "spearman",size = 8) + theme 手动计算的结果与原文相似性更高,很有意思 EMT基因来源 —— 网页数据库EMTome(http://www.emtome.org/) 该数据库主要包括五个模块:EMT Signature、EMT Genes、EMT Interactome、EMT Score、CRISPR/DRUG Response: ...
为方便快捷的解决这个问题,使用ggpubr包stat_cor就可以实现。 首先计算相关系数,然后使用函数annotate添加: library(ggplot2) data(mtcars) df <- mtcars df$cyl <- as.factor(df$cyl) cor.test(df$mpg,df$wt) b <- ggplot(df, aes(x = wt, y = mpg)) # Scatter plot with regression line b +...
ggplot(data,aes(x=age,y=Time))+geom_point(data,mapping=aes(x=age,y=Time),size=2)+geom_smooth(aes(x=age,y=Time),method='lm',level=0.95,se=F,size=1.6)+stat_cor(method="spearman",label.x.npc="left",label.y.npc=0.97)+#或pearsontheme_bw() ...
p4<-ggscatter(mydf,x="DPS",y="ISG",add="reg.line",conf.int=T)+labs(y="Mean ISG module score",x="Days post-symptom onset")+stat_cor(label.x=8,label.y=0.2) 最后是拼图 代码语言:javascript 复制 ggarrange(p1,p2,p3,p4,ncol=2,nrow=2,labels=c("p1","p2","p3","p4")) ...
)+stat_cor(method = "pearson", label.x = 0.15, label.y = 30)+xlim(0,0.44)+ xlab("gene1") + ylab('gene2) theme(axis.title.x = element_text(size = 16, face = "bold", vjust = 0.5, hjust = 0.5))+ ylab("gene2") + ...
stat_smooth(method="lm",se=FALSE, formula=y~x)+labs(x="",y="",title = paste0(Gene,", ",Drug),subtitle = paste0("Cor=",cor,", ",pvalue))+theme(axis.ticks = element_blank(), axis.text.y = element_blank(),axis.text.x = element_blank())+theme_bw()plotList[[i]]=p1}...