R 如何使用stat_ellipse更改ggplot2中椭圆的线型?
因此,我试图更改由ggplot2中的stat_ellipse生成的椭圆上的线型(请参见此处)。我可以很容易地手动设置颜色,但我想给它一个线型向量,它会改变椭圆的线型。我尝试过在stat_eliple()函数中设置线型,也尝试过在+scale_linetype_手册中单独设置线型,但在stat_eliple函数中似乎只有一个线型值起作用,scale_linetype_手册没有任何作用。任何建议都将不胜感激 基本代码和示例图像如下所示R 如何使用stat_ellipse更改ggplot2中椭圆的线型?,r,ggplot2,pca,ellipse,R,Ggplot2,Pca,Ellipse,因此,我试图更改由ggplot2中的stat_ellipse生成的椭圆上的线型(请参见此处)。我可以很容易地手动设置颜色,但我想给它一个线型向量,它会改变椭圆的线型。我尝试过在stat_eliple()函数中设置线型,也尝试过在+scale_linetype_手册中单独设置线型,但在stat_eliple函数中似乎只有一个线型值起作用,scale_linetype_手册没有任何作用。任何建议都将不胜感激 基本代码和示例图像如下所示 ggplot(data.df,aes(x = PC1,y =PC
ggplot(data.df,aes(x = PC1,y =PC2, color = mapping$Description))+
geom_point(size=5,aes(shape=factor(mapping$Status)))+
stat_ellipse(aes(x = PC1,y=PC2,fill=factor(mapping$Description)),
geom="polygon",level=0.8,alpha=0.2)+
scale_fill_manual(values=c("red","red","green","blue","blue"))
映射$。。。这些只是一些因素。PC1和PC2只是包含主要组件和数据的向量。df只是一个包含所有这些内容的数据帧
可以通过首先指定线型作为统计椭圆aes中的一个因子,然后按照用户aosmith在评论中指出的比例线型手册来更改线型
ggplot(data.df,aes(x = PC1,y =PC2, color = mapping$Description))+
geom_point(size=5,aes(shape=factor(mapping$Status)))+
stat_ellipse(aes(x = PC1,y=PC2,lty=factor(mapping$Status),fill=factor(mapping$Description)),
geom="polygon",level=0.8,alpha=0.2)+
scale_fill_manual(values=c("red","red","green","blue","blue"))+
scale_linetype_manual(values=c(1,2,1,2,1))
您能否将您尝试使用的
线型
与您的数据一起添加?如果要将变量映射到线型
,请将其放入全局或统计椭圆
aes
中。然后,您可以使用scale\u linetype\u manual
控制每个组使用哪些行。