我是 R 的新手。我试图使用 pca 和 ggbiplot 来显示 pca 结果,但不知何故陷入了一些我无法解决的错误。也许我的数据有问题,因为代码可以很好地处理其他数据。我将我使用的代码和数据文件放在以下链接中,以防您想重新创建场景:-
https://drive.google.com/drive/folders/0B2jQ7Vh3S3PaZkt3Y2ZyaV9XaXc
代码:pca-plot.R 数据文件 1:dat1.rda(这个工作正常) 数据文件 2:dat2.rda(这个有问题)
感谢任何帮助。我得到的错误在底部。
谢谢,--我们
> g <- ggbiplot(tr.pca, obs.scale = 1, var.scale = 1,
+ groups = Ydfall,
+ ellipse = TRUE,
+ circle = TRUE)
Error in `$<-.data.frame`(`*tmp*`, "groups", value = c(1L, 1L, 1L, 1L, :
replacement has 36 rows, data has 35
> g <- g + scale_color_discrete(name = '')
Scale for 'colour' is already present. Adding another scale for 'colour', which will replace the existing scale.
> g <- g + theme(legend.direction = 'horizontal',
+ legend.position = 'top')
> g<- g+ geom_point(size=1, shape=1, color="black", stroke=2)
>
> print(g)
>