【问题标题】:Customize border of ggbiplot points自定义 ggbiplot 点的边框
【发布时间】:2016-11-02 18:35:51
【问题描述】:

使用devtools::install.github() 提供的 ggbiplot 库给出以下代码:

library(ggbiplot)
data(iris)
log.ir <- log(iris[, 1:4])
ir.species <- iris[, 5]

ir.pca <- prcomp(log.ir, center = TRUE, scale. = TRUE)

g <- ggbiplot(ir.pca, obs.scale = 1, var.scale = 1, groups = ir.species)
g <- g + theme(legend.direction = 'vertical', legend.position = 'right')
g <- g + scale_color_manual(values=c("blue", "red", "green"))
print(g)

根据分组自定义数据点边界的最佳方法是什么?我使用 scale_color_manual() 来自定义这些数据点的颜色,但我想不出一种方法来为边框做到这一点。

谢谢

【问题讨论】:

  • 您要调整点边框还是情节边框的颜色?

标签: r ggplot2 ggbiplot


【解决方案1】:

假设您想自己调整数据点的边框...

ggbiplot() 调用本身不会为您提供这种灵活性,但设置 alpha = 0 将使ggbiplot 绘制的点不可见或真正 100% 透明。然后,您可以使用geom_point() 调用创建一个单独的图层,在其中将shape 指定为具有填充(中间)和颜色(边界)美学的5 个形状(21-25)之一。

ggbiplot(ir.pca, obs.scale = 1, var.scale = 1, groups = ir.species, alpha = 0) +
    theme(legend.direction = 'vertical', legend.position = 'right') + 
    scale_color_manual(values=c("blue", "red", "green")) +
    scale_fill_manual(values = c("red", "green", "blue")) + # just offset by one to show
    geom_point(size = 3, shape = 21, aes(fill = groups, color = groups))

PS 在您的问题中包含您正在使用的软件包只能通过devtools::install.github() 获得而不是标准的install.packages() 可能总是一个好主意

【讨论】:

  • 非常感谢!我将更改原始帖子并包含 devtools 信息。
  • 在这种情况下,你如何避免绘制的箭头?
  • 好问题,我不知道,但我会玩弄它
  • 看起来ggbiplot() 的默认设置是将点分层,可能会将大小减小到 1 以最小化箭头覆盖率,或者可能使用 alpha 或空心形状。对不起,我不能给你更好的答案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-02-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多