gpt4 book ai didi

r - ggbiplot - 更改组颜色和标记

转载 作者:行者123 更新时间:2023-12-04 12:16:15 25 4
gpt4 key购买 nike

在示例 ggbiplot 脚本图中有 3 组,如何更改标记颜色和形状?

library(ggbiplot)
data(wine)
wine.pca <- prcomp(wine, scale. = TRUE)
ggbiplot(wine.pca, obs.scale = 1, var.scale = 1, group=wine.class,
varname.size = 3, labels.size=3,
ellipse = TRUE, circle = TRUE) +
scale_color_discrete(name = '') +
geom_point(aes(colour=wine.class), size = 3) +
theme(legend.direction ='horizontal',
legend.position = 'top')

最佳答案

以下对我有用。

ggbiplot(wine.pca, obs.scale = 1, var.scale = 1, group=wine.class,
varname.size = 3, labels.size=3, ellipse = TRUE, circle = TRUE) +
scale_color_manual(name="Variety", values=c("orange", "purple", "green")) +
scale_shape_manual(name="Variety", values=c(17:19)) +
geom_point(aes(colour=wine.class, shape=wine.class), size = 3) +
theme(legend.direction ="horizontal",
legend.position = "top")

enter image description here

对于图例,诀窍似乎是使用相同的 namescale_color_manualscale_shape_manual .

关于r - ggbiplot - 更改组颜色和标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40287943/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com