PCA ggplot绘图中能否将变量箭头替换为仅显示点和标签
ggbiplot绘制PCA双标图时隐藏变量箭头、仅展示点与标签的方法
可以实现,只需调整ggbiplot的内置参数即可,操作方案如下:
方案1:仅隐藏变量箭头,保留样本点与分组信息
在ggbiplot函数中添加参数var.axes = FALSE即可关闭变量箭头绘制,修改后代码如下:
biplot <- ggbiplot(pcobj = PCA, choices = c(1,2), scale = 1, groups = Fdata$Tissue, ellipse = TRUE, var.axes = FALSE) + geom_vline(xintercept = 0, linetype = 3) + geom_hline(yintercept = 0, linetype = 3) + geom_point(aes(shape = factor(Fdata$Tissue))) + guides(color = "none", shape = guide_legend(title = "Tissue")) + scale_shape_discrete(labels = c("Flesh","Gill"))
方案2:隐藏箭头同时展示变量的点与对应标签
如果需要在原箭头位置显示变量对应的点和名称标签,额外添加变量点、标签控制参数即可,修改后代码如下:
biplot <- ggbiplot(pcobj = PCA, choices = c(1,2), scale = 1, groups = Fdata$Tissue, ellipse = TRUE, var.axes = FALSE, var.point.size = 3, var.label = TRUE, var.label.size = 3.5) + geom_vline(xintercept = 0, linetype = 3) + geom_hline(yintercept = 0, linetype = 3) + geom_point(aes(shape = factor(Fdata$Tissue))) + guides(color = "none", shape = guide_legend(title = "Tissue")) + scale_shape_discrete(labels = c("Flesh","Gill"))
参数说明
var.axes默认值为TRUE,控制是否绘制变量箭头,设为FALSE后即可隐藏箭头- 可根据可视化需求调整
var.point.size(变量点大小)、var.label.size(变量标签字体大小)的数值
内容的提问来源于stack exchange,提问作者Sonam Tashi
相关产品推荐
相关产品推荐

