我有从vegan metaMDS中提取的data.frame,如下所示:
MDS1 MDS2 time nucleic_acid habitat treatment
10dnawatercontrol 0.06297458 0.153364604 10 dna water control
10dnawatertreated -0.20010385 -0.241614081 10 dna water treated
11dnawatercontrol 0.15518683 0.067861388 11 dna water control
11dnawatertreated -0.12137470 -0.258434255 11 dna water treated
12dnawatercontrol -0.02041011 0.140458063 12 dna water control
12dnawatertreated -0.36101682 -0.110667764 12 dna water treated
13dnawatercontrol -0.19054474 0.287597321 13 dna water control
13dnawatertreated -0.26751484 -0.092326331 13 dna water treated
14dnawatercontrol -0.10942501 0.208263588 14 dna water control
14dnawatertreated -0.33594573 0.015625565 14 dna water treated
15dnawatercontrol -0.06631137 0.226240078 15 dna water control
15dnawatertreated -0.27606083 -0.019999889 15 dna water treated
16dnawatercontrol 0.01703248 0.132900239 16 dna water control
16dnawatertreated -0.32565421 -0.022154859 16 dna water treated
17dnawatercontrol -0.25806806 0.201731201 17 dna water control
17dnawatertreated -0.40662186 -0.003830044 17 dna water treated
18dnawatercontrol -0.17699110 0.184587876 18 dna water control
18dnawatertreated -0.46597548 -0.022633769 18 dna water treated
19dnawatercontrol -0.28119311 0.197837800 19 dna water control
19dnawatertreated -0.62468238 0.187704606 19 dna water treated
4dnawatercontrol 1.23658067 0.660553669 4 dna water control
4dnawatertreated 0.85195731 -0.740790358 4 dna water treated
5dnawatercontrol 0.66159385 0.183955243 5 dna water control
5dnawatertreated 0.36367763 -0.446656965 5 dna water treated
6dnawatercontrol 0.19736034 0.206992740 6 dna water control
6dnawatertreated -0.04189317 -0.273487207 6 dna water treated
7dnawatercontrol 0.35362061 -0.005658852 7 dna water control
7dnawatertreated 0.14481323 -0.409432041 7 dna water treated
8dnawatercontrol 0.30718548 0.072991390 8 dna water control
8dnawatertreated 0.13210812 -0.311147579 8 dna water treated
9dnawatercontrol 0.20028730 0.065109821 9 dna water control
9dnawatertreated -0.15459106 -0.234941197 9 dna water treated
我正在用ggplot2绘制这些数据:
ggplot()+
geom_point(data=meta_nmds_water_dna,aes(x=MDS1,y=MDS2,shape=treatment,colour=time),size=3)+
geom_line(data=meta_nmds_water_dna,aes(x=MDS1,y=MDS2,group=treatment,colour=time),size=1)+
geom_text(data=meta_nmds_water_dna,aes(x=MDS1,y=MDS2,label=time,size=6,vjust=0))
正如您所看到的,geom_points是根据x值连接的,但我希望通过" time" -factor连接它们,您知道这样做的方法吗?
答案 0 :(得分:0)
ggplot() +
geom_point(data=meta_nmds_water_dna,aes(x=MDS1,y=MDS2,shape=treatment,colour=time),size=4) +
geom_path(data=path,aes(x=MDS1,y=MDS2,group=treatment,colour=as.numeric(as.character(time))),size=1.5)+
geom_text(data=meta_nmds_water_dna,aes(x=MDS1,y=MDS2,label=time,size=5,vjust=-0.7)) +
coord_equal()
我完全得到了我想要的东西。但请确保您的数据顺序正确:
path<-meta_nmds_water_dna
path$time<-as.numeric(as.character(path$time))
path<-path[order(path$time),]