ggplot(plotdata,aes(x=RDA1,y=RDA2,color=plotdata$Group))+ geom_point(size=4,aes(color = plotdata$Group,shape=plotdata$Treatment))+ stat_ellipse(aes(fill=plotdata$Group),geom = "polygon",linewidth=0.6,level = 0.95,alpha = 0.1)+ geom_segment(data=RDAE,aes(x = 0, y = 0, xend = RDAE[,1]*3.5, yend = RDAE[,2]*3.5), arrow = arrow(length = unit(0.03, 'npc')),linewidth =1,color="gray2")+ geom_text(data = RDAE,aes(RDA1 * 4,RDA2 * 4,label = rownames(RDAE)),color = 'gray2',size = 4)+ xlab(paste("RDA1 (",rda1,"%",")"))+ylab(paste("RDA2 (",rda2,"%",")"))+ theme_bw(base_line_size = 1.05,base_rect_size = 1.05)+ scale_color_manual(values=c("#3FBDA7","#0172B6","#BD3C29","#F0965D","#BEBADA"))+ scale_shape_manual(values = c(1,2,3))+ theme(panel.grid.major=element_blank(),panel.grid.minor=element_blank())+ geom_hline(aes(yintercept=0), colour="gray45",size=0.8, linetype="dashed")+ geom_vline(aes(xintercept=0), colour="gray45",size=0.8, linetype="dashed") 请修改R脚本,将图例名修改为Bac,同时将填充图例与颜色图例合并表示
时间: 2023-11-09 17:04:35 浏览: 144
可以使用scale_color_manual()函数和scale_fill_manual()函数来修改图例名和合并填充图例与颜色图例。
修改后的代码如下:
ggplot(plotdata,aes(x=RDA1,y=RDA2,color=plotdata$Group, fill=plotdata$Group))+
geom_point(size=4,aes(shape=plotdata$Treatment))+
stat_ellipse(aes(fill=plotdata$Group),geom = "polygon",linewidth=0.6,level = 0.95,alpha = 0.1)+
geom_segment(data=RDAE,aes(x = 0, y = 0, xend = RDAE[,1]*3.5, yend = RDAE[,2]*3.5),
arrow = arrow(length = unit(0.03, 'npc')),linewidth =1,color="gray2")+
geom_text(data = RDAE,aes(RDA1 * 4,RDA2 * 4,label = rownames(RDAE)),color = 'gray2',size = 4)+
xlab(paste("RDA1 (",rda1,"%",")"))+ylab(paste("RDA2 (",rda2,"%",")"))+
theme_bw(base_line_size = 1.05,base_rect_size = 1.05)+
scale_color_manual(name="Bac", values=c("#3FBDA7","#0172B6","#BD3C29","#F0965D","#BEBADA"))+
scale_fill_manual(name="Bac", values=c("#3FBDA7","#0172B6","#BD3C29","#F0965D","#BEBADA"))+
scale_shape_manual(values = c(1,2,3))+
theme(panel.grid.major=element_blank(),panel.grid.minor=element_blank())+
geom_hline(aes(yintercept=0), colour="gray45",size=0.8, linetype="dashed")+
geom_vline(aes(xintercept=0), colour="gray45",size=0.8, linetype="dashed")
阅读全文