【问题标题】:Autoplot for prcomp - changing symbolsprcomp 的自动绘图 - 更改符号
【发布时间】:2017-03-10 08:02:48
【问题描述】:

我有一点阴谋诡计,我希望你们都能为我提供一个快速简单的答案。我使用 prcomp() 运行 PCA,并第一次尝试使用 ggplot 绘制它。我成功地制作了一个美观的人物,但我刚刚让同事指出它目前对色盲不友好。

我使用的配色方案不容易更改(因为此 PCA 图需要与之协调的许多其他图形),所以我一直在尝试更改我的图形以包含每个组的不同符号。

我发现另一个post 提到使用 scale_shape_manual() 添加这些符号,但是当我尝试实现它时,符号类型不会改变。它也没有给我一个错误,这让我不确定从哪里开始故障排除。

下面是大家最喜欢的 PCA 数据集 iris 示例:

library(ggplot2)
library(ggfortify)

df <- iris[c(1, 2, 3, 4)]
iris.pca<-(prcomp(df))

autoplot(iris.pca, data=iris, colour="Species", frame=TRUE)+
  scale_colour_manual(values=c("forestgreen","red","blue"))+
  scale_fill_manual(values=c("forestgreen","red","blue"))+
  scale_shape_manual(values=c(25,22,23))+
  theme_bw()

如果有人对如何轻松更改这些符号或其他更适合此类更改的绘图功能提出建议,我将不胜感激。

【问题讨论】:

  • 我会简单地添加shape="Species"
  • 成功了,谢谢!

标签: r plot ggplot2 pca


【解决方案1】:

简单的解决方案如下(shape="Species" 需要添加到原来的autoplot函数中):

library(ggplot2)
library(ggfortify)

df <- iris[c(1, 2, 3, 4)]
iris.pca<-(prcomp(df))

autoplot(iris.pca, data=iris, colour="Species", shape="Species",frame=TRUE)+
  scale_colour_manual(values=c("forestgreen","red","blue"))+
  scale_fill_manual(values=c("forestgreen","red","blue"))+
  scale_shape_manual(values=c(25,22,23))+
  theme_bw()

【讨论】:

    猜你喜欢
    • 2015-07-15
    • 2017-12-11
    • 1970-01-01
    • 2020-10-12
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    • 2020-05-18
    • 2012-12-17
    相关资源
    最近更新 更多