||
问题: 使用ggplot2的分面 facet之后如何 给分面的画布添加文字?
图片:
解决方法:
### 使用数据
head(SSdat)
ProID SS RSA PredRSA
1 1a1xA C 1.0000000 0.9972860
2 1a1xA C 1.0000000 0.9894930
3 1a1xA C 0.4368421 0.3556108
4 1a1xA C 1.0000000 0.9548766
5 1a1xA C 0.1612903 0.1963138
6 1a1xA C 0.7733333 0.6331485
###
myggp<-ggplot(data=SSdat,aes(x=PredRSA,y=RSA,group=SS))+
geom_point(size=0.5,alpha=0.3)+
facet_wrap(~SS)+ #分面
geom_smooth(formula=y~x, method = "lm",alpha=0.6,size=1.4)+ #添加回归直线
theme_bw() #白色背景
## 产生数据框, 为了给文字坐标
data_text<-data.frame(label=c("PCC=0.891","PCC=0.845","PCC=0.901"),
SS=c("C","E","H"),
x=c(0.15,0.15,0.15),
y=c(0.95,0.95,0.95))
####
####data_text
# label SS x y
#1 PCC=0.891 C 0.15 0.95
#2 PCC=0.845 E 0.15 0.95
#3 PCC=0.901 H 0.15 0.95
### 为每幅画 添加文字。
myggp+geom_text(data=data_text,
mapping=aes(x=x,y=y,label=label),nudge_x=0.1,nudge_y=0.1)
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-12-28 10:31
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社