有什么方法可以从R包fviz_pca_biplot() FactoExtra中指定变量的形状吗?
例如,我有以下代码:
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)但是它使var和ind的形状相同,我希望var的形状是不同的(形状15)。当geom.var = c(" point“、"text")设置为point时,参数”切入点“似乎同时适用于var和ind。
我尝试过使用scale_shape_manual():
BiPlot+
scale_shape_manual(values=15) 但是它不适用,我猜想这是由于geom中的" point“在geom中使用geom_point,并且我不能指定我想要应用它的点,但这只是一个粗略的猜测。
可以将var和ind的点形状设置为不同的值吗?
发布于 2021-12-12 19:12:09
您只对fviz_pca_biplot中的数据点使用"text“,这将确保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()

https://stackoverflow.com/questions/64267037
复制相似问题