我想将带有direct.labels的标签添加到我的 Gower 残差图中(用于适用性分析)。但是,我发现direct.labels函数仅将标签添加到某些点,而不是所有点。我想知道是否有一个函数可以使用direct.lables做到这一点,或者有人可以向我推荐一种更好的方法。
谢谢
这是我正在使用的代码
#Loading the data frame "R" to be used with ggplot
R <- read.csv(header=T, text='
Sector,Group,Type,Value
SBF,1,Residual,0.03
SBF,4,Residual,-0.06
SBF,5,Residual,-0.02
SBF,6,Residual,0.07
SDF,1,Residual,0.13
SDF,4,Residual,-0.08
SDF,5,Residual,0.08
SDF,6,Residual,0.03
SPF,1,Residual,0.04
SPF,4,Residual,0.16
SPF,5,Residual,-0.11
SPF,6,Residual,-0.08
SOF,1,Residual,0
SOF,4,Residual,0.16
SOF,5,Residual,0.32
SOF,6,Residual,-0.48
SSF,1,Residual,0
SSF,4,Residual,-0.06
SSF,5,Residual,0.01
SSF,6,Residual,0.2
SCO,1,Residual,-0.21
SCO,4,Residual,-0.06
SCO,5,Residual,0.07
SCO,6,Residual,0.2
SMA,1,Residual,0.28
SMA,4,Residual,-0.04
SMA,5,Residual,-0.17
SMA,6,Residual,-0.07
SNT,1,Residual,-0.11
SNT,4,Residual,-0.01
SNT,5,Residual,0
SNT,6,Residual,0.13
')
## Converting integers into factors so i can make groups of sectors
R$Group<-factor(R$Group)
install.packages("directlabels")
library(directlabels)
## Creating p for the direct.labels function using ggplot
p<-ggplot(data=R, aes(x=Group, y=Value, group=Sector, colour=Sector))+
geom_text(aes(label=format(Sector),
size=3,
hjust=-0.2,
vjust=-0.05),
show_guide=FALSE)+
geom_segment(aes(xend=Group),yend=0,colour="grey50",linetype="solid")+
geom_hline(aes(yintercept=0), linetype="solid")+
geom_point(size=3)+
scale_x_discrete(labels=c(
"1"="Group 1",
"2"="Group 2",
"3"="Group 3",
"4"="Group 4",
"5"="Group 5",
"6"="Group 6"),
expand=c(0.13,0.05))+
scale_y_continuous()+
theme_bw()+
theme(panel.grid.minor=element_blank(),
panel.grid.major=element_blank(),
axis.title.x=element_blank(),
axis.title.y=element_blank(),
axis.text.x=element_text(size=13,
face="bold",
hjust=0.5),
axis.text.y=element_text(size=10,
face="bold",
hjust=0.5))
direct.label(p,dl.combine(first.qp,last.qp))