作为对这个非常有用的问题和答案的跟进:
Color-coding 95% confidence ellipses for centroids
我已经成功地在ggplot中为我的NMDS图重叠了置信椭圆。我现在想要指定绘图上数据点的颜色和形状,以及椭圆的颜色和线型,以区分我的四种处理。
NMDS在这里:
Dat2在这里:
我尝试过的代码如下:
ggplot(data = NMDS, aes(MDS1, MDS2)) + geom_point(aes(color = group)) +
geom_path(data=Dat2, aes(x=NMDS1, y=NMDS2,colour=group), size=1, linetype=2)+theme(axis.title.y=element_text(size=rel(1.1),vjust=0.2),axis.title.x=element_t ext(size=rel(1.1),vjust=0.2),axis.text.x=element_text(size=rel(1)),axis.text.y=element_text(size=rel(1)),text = element_text(size=13)) +scale_shape_manual(name = "Treatment", labels = c("W+N-", "W+NC", "WCN-", "WCNC"),
values = c("17", "19","17", "19")) +scale_colour_manual(name = "Treatment", labels = c("W+N-", "W+NC", "WCN-", "WCNC"),
values = c("blue", "blue","red", "red")) +scale_linetype_manual(name = "Treatment", labels = c("W+N-", "W+NC", "WCN-", "WCNC"),
values = c("3", "1","3", "1"))
不幸的是,只有点和椭圆的颜色似乎有效 - 椭圆的线型和数据点的形状似乎没有变化。有没有人建议如何解决这个问题?
非常感谢!
答案 0 :(得分:1)
您需要将linetype
和shape
映射到group
,就像将color
映射到group
一样。实际上,您可以在第一行中执行这两次映射,因为两个数据集中变量的名称相同:
ggplot(data = NMDS, aes(MDS1, MDS2, color=group, linetype=group, shape=group))
当然,您需要删除其他地方的color
和linetype
映射。您还应该将linetype
中的scale_linetype_manual
值指定为数字,而不是字符串。最后,你会有这样的事情:
ggplot(data = NMDS, aes(MDS1, MDS2, color=group, linetype=group, shape=group)) +
geom_point() +
geom_path(data=Dat2, aes(x=NMDS1, y=NMDS2), size=1) +
theme(axis.title.y=element_text(size=rel(1.1),vjust=0.2),axis.title.x=element_text(size=rel(1.1),vjust=0.2),axis.text.x=element_text(size=rel(1)),axis.text.y=element_text(size=rel(1)),text = element_text(size=13)) +
scale_shape_manual(name = "Treatment", labels = c("W+N-", "W+NC", "WCN-", "WCNC"), values = c(17, 19,17, 19)) +
scale_colour_manual(name = "Treatment", labels = c("W+N-", "W+NC", "WCN-", "WCNC"), values = c("blue", "blue","red", "red")) +
scale_linetype_manual(name = "Treatment", labels = c("W+N-", "W+NC", "WCN-", "WCNC"), values = c(3, 1,3, 1))