ggbiplot - how not to use the feature vectors in the plot

拟墨画扇 提交于 2019-12-03 17:17:34

I cannot quite figure out how this would yield a useful result, but here goes anyway. The names are not something that the function lets you suppress via parameter settings, at least to my reading of the code and help page. So looking at the code it looks as though the labels for the factors are pulled from the $rotations element of the prcomp object. Trying to set those names all to a blank character created an error so I succeeded by setting to the a value of varying lengths of blanks.

data(wine)    # need a reproducible example so use the help page 
 wine.pca <- prcomp(wine, scale. = TRUE)
print(ggbiplot(wine.pca, obs.scale = 1, var.scale = 1, groups = wine.class, ellipse = TRUE, circle = TRUE))
# that was the equivalent of your plot
# Now change the input value

dimnames(wine.pca$rotation)[[1]] <- 
   Reduce(function(x,y) paste0(x,y),    # function to concatentate the lanks
          rep(" ",dim(wine.pca$rotation)[1]),   # corrrect number of blanks
           acc=TRUE)                    # save all intermediate strings
 print(ggbiplot(wine.pca, obs.scale = 1, var.scale = 1, groups = wine.class, 
        ellipse = TRUE, circle = TRUE))
 #Look, Ma! No labels

Anca

I can't just comment because I don't have the necessary reputation points yet, but removing the arrows and the names works quite easily by setting var.axes to false:

ggbiplot(wine.pca, obs.scale = 1, var.scale = 1, 
         groups = wine.class, ellipse = TRUE, 
         circle = TRUE, var.axes=FALSE)

You need to use the varname.size argument to do that.

Using the example from the documentation:

data(wine)
wine.pca <- prcomp(wine, scale. = TRUE)
print(ggbiplot(wine.pca, obs.scale = 1, var.scale = 1, 
               groups = wine.class, ellipse = TRUE, circle = TRUE))

and then add the varname.size argument:

print(ggbiplot(wine.pca, obs.scale = 1, var.scale = 1, 
               groups = wine.class, ellipse = TRUE, circle = TRUE,
               varname.size=0)) #set it to zero

And you have what you want!

Ok, so I do this in a very brute way that does the job.

    print(ggbiplot(wine.pca, obs.scale = 1, var.scale = 1,
           groups = wine.class, ellipse = TRUE, circle = TRUE,
           varname.size=0, varname.adjust = 20))

It simply sets the offset for variable names beyond the plot limits.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!