我是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)
>
答案 0 :(得分:0)
来自dfall
的{{1}} dat2.rda
NA
(尝试which(is.na(dfall), arr.ind = T)
),这会导致您的问题。您在使用na.omit()
时使用了prcomp()
,但在使用Ydfall
时未使用Ydfall <- na.omit(dfall)[,1] # quick fix
# but if I were you, I would do first;
dfall <- na.omit(dfall)
。
{{ ansible_all_ipv4_addresses }}