简体   繁体   English

在 fviz_pca_biplot 中为 var 和 ind 指定不同的点形状

[英]Specify different pointshapes for var and ind in fviz_pca_biplot

Is there any way of specifying shape for variables in fviz_pca_biplot() from R package FactoExtra?有没有办法在 R 包 FactoExtra 中为fviz_pca_biplot()变量指定形状?

For example I have the following code:例如,我有以下代码:

data("iris")

PCA.iris <- prcomp(iris[ , -5], scale=TRUE)

BiPlot<- fviz_pca_biplot(PCA.iris, 
                      geom = c("point", "text"), 
                      geom.var = c("point", "text"),
                      palette="ucscgb",
                      label="var",       
                      col.ind=iris$Species,
                      invisible="quali",
                      pointshape = 19, pointsize = 3) +
                      labs(colour= "Species" )+
                      theme_gray() +
                     theme(plot.title = element_text(hjust = 0.5,size = 20, face = "bold"),
                           legend.title = element_text(size = 12), 
                           legend.text = element_text(size = 8),
                           legend.key.size = unit(0.5,"line") )+
                     guides(shape = guide_legend(override.aes = list(size = 4)),
                           color = guide_legend(override.aes = list(size = 4)) )
print(BiPlot)

but it makes the shape for both var and ind the same, I would like the shape for var to be different (shape 15).但它使varind的形状相同,我希望var的形状不同(形状 15)。 The argument "pointshape" seems to apply to both var and ind when geom.var = c("point", "text") is set to point.当 geom.var = c("point", "text") 设置为 point 时,参数“pointshape”似乎同时适用于varind

I have tried using scale_shape_manual() :我曾尝试使用scale_shape_manual()

 BiPlot+
 scale_shape_manual(values=15) 

but it does not apply, I am guessing that this is due to "point" in geom uses geom_point and I can not specify to which point I want to apply it but this is just a wild guess.但它不适用,我猜这是由于 geom 中的“点”使用 geom_point 并且我无法指定我想将它应用到哪个点,但这只是一个疯狂的猜测。

Is it possible to set pointshape for var and ind to different values and how is it done then?是否可以将varind 的pointshape 设置为不同的值,然后如何完成?

You use only "text" for your data points in fviz_pca_biplot and this will ensure your var shape is 15. Then you call another geom_point() for your individual datapoints and specify the shape:您只对fviz_pca_biplot的数据点使用“文本”,这将确保您的 var 形状为 15。然后您为您的各个数据点调用另一个 geom_point() 并指定形状:

library(ggsci)
library(factoextra)

data("iris")

PCA.iris <- prcomp(iris[ , -5], scale=TRUE)

BiPlot<- fviz_pca_biplot(PCA.iris, 
                      geom = "text", 
                      geom.var = c("point", "text"),
                      label="var",
                      col.ind=iris$Species,       
                      invisible="quali",
                      pointshape = 15, pointsize = 3) +
                      geom_point(aes(col = Col.),shape=10)+
                      labs(colour= "Species" )+
                      scale_color_ucscgb() +
                      theme_gray() 
                 

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM