R - 将类似对象的矩阵(超过 3 个值)转换为 RGB 系统

R - Translate matrix like object (more than 3 values) into RGB system

我有以下数据:

head(spca,3)
        Axis 1       Axis 2     Axis 3      Axis 4    Axis 5
P2    0.41785706 -2.215135138  1.1873094 -1.90061886  1.42734543
P92  -3.10662325  2.062759336  2.9738782  0.34503630 -2.4026353
P144 -4.68879566  2.090462774  3.7421616  0.03259024  1.046545319

head(coord,3)
    Longitude Latitude
P2   35.13092 32.51011
P92  35.34025 32.55186
P144 35.47386 32.85336

我使用 adegenet 包中的 colorplot 命令为行创建颜色。该命令使用 spca table 并将其转换为 RGB 系统。

plot(c(34.6,35.9),c(31.2,33.5),cex=.01, ylab="",xlab="")
colorplot(coord, spca1, axes=1:5, transp=TRUE, add=TRUE,cex=2.5)   

但我实际上想在 ggplot 上绘制此图,其中 colorplot 不起作用,我需要颜色渐变来表示 5 轴所描述的行关系。所以我想知道如何自己创建像 colorplot 这样的颜色以在 ggplot 的 geom_point?

中使用它

有什么想法吗?

谢谢

由于缺乏测试数据集,这可能仍然可以回答。

为了找到这些类型问题的答案,请先尝试 ?colorplothelp(colorplot)。看下面的'value section',里面介绍了returns 的功能,以供进一步使用。这里我们被告知该函数将 return 绘图期间使用的颜色。

plot(c(34.6,35.9),c(31.2,33.5),cex=.01, ylab="",xlab="")
colours <- colorplot(coord, spca1, axes=1:5, transp=TRUE, add=TRUE,cex=2.5) 
ggplot(data = coords)+geom_point(aes(x = <column 1 name>, y = <column 1 name>), 
                                 col = colours, size = 2.5)                       

应该给你相同(或相似)的答案(更改 aes(...) 参数中的坐标以匹配你的数据,并根据你的喜好更改大小)。