这是仅使用的解决方案ggplot2
,因此它不是最优雅的解决方案。
我按照@Eric Fail 的建议开始了第一步。
require(vegan)
data(dune)
data(dune.env)
# RDA
RDA <- rda(dune ~ A1, data = dune.env)
# extract species scores
df1 <- data.frame(RDA.scores = scores(RDA)$sites[ , 1], Management = dune.env$Management)
df2 <- data.frame(y = scores(RDA)$species[ , 1], taxa = rownames(scores(RDA)$species))
# Order data according to species scores
df2<-df2[order(df2$y),]
# define values for rugs (segments). 4.9 and 5.0 used because data has 4 levels (+1)
df2$x=4.9
df2$xend=5
# define coordinates for names (30 is number of species)
df2$yend2<-seq(min(df1$RDA.scores),max(df1$RDA.scores),length.out=30)
df2$xend2=5.3
# plot
P <- ggplot(data = df1, aes( x = Management, y = RDA.scores) ) +
geom_segment(y=0,yend=0,x=0,xend=5, lty=2, size = I(0.3)) +
geom_boxplot() +
#add extra levels to get space
scale_x_discrete(limits=c("BF", "HF", "NM", "SF", "","")) +
#set y scale
scale_y_continuous(limits=c(-3,5),expand=c(0,0)) +
#add rugs as segments and add segments connecting rugs and texts
geom_segment(data= df2, mapping=aes(x=x,xend=xend,y=y,yend=y), size = I(0.3)) +
geom_segment(data= df2, mapping=aes(x=xend,xend=xend2,y=y,yend=yend2), size = I(0.4)) +
#add texts
geom_text(data=df2,mapping=aes(x=xend2+0.1,y=yend2,label=taxa),hjust=0, size=3) +
#add rectangular to imitate box around plot
geom_rect(xmax=5,xmin=0.4,ymax=5,ymin=-3,colour="black",fill=NA)
# Final adjustments of plot
P+theme(axis.line=element_blank(),
panel.grid=element_blank(),
panel.background=element_blank())