如何去除R中fviz_pca_biplot处圆圈的边框线?

问题描述 投票:0回答:2

我有以下一项数据

df<-structure(list(SEASON = c("Low D", "Low D", "Low D", "Low D",  "Low D", "Low D", "Low D", "Low D", "Low D", "Low D", "High D",  "High D", "High D", "High D", "High D", "High D", "High D", "High D",  "High D", "High D"), GENOTYPE = c("A", "B", "C", "D", "E", "F",  "G", "H", "I", "J", "A", "B", "C", "D", "E", "F", "G", "H", "I",  "J"), Y1 = c(16.95, 16.25, 16.1, 16.25, 17.25, 17.7, 15.75, 17.5,  16.9, 16.95, 15.95, 16.15, 15.4, 15.45, 16.5, 17, 15.8, 17.5,  16.55, 16.95), Y2 = c(36.325, 35.425, 38.175, 36.3, 35.225, 36,  35, 33.15, 34.975, 35.35, 29.55, 30.225, 33.35, 30.7, 30.35,  30.8, 31.95, 27.5, 30.075, 28.825), Y3 = c(242.475, 237.15, 234.307692307692,  243.75, 232.575, 257.4, 223.875, 241.35, 235.65, 239.275, 163.85,  177.4, 158.675, 171.95, 161.625, 181.65, 173.175, 166.05, 174.717948717949,  178.875), Y4 = c(206.375, 206.525, 206.230769230769, 210.925,  201.7, 223.5, 199.725, 211.8, 206.525, 211.75, 141.175, 154.075,  142.575, 148.925, 140.675, 157.65, 155.475, 143.35, 153.230769230769,  155.575), Y5 = c(70.775, 71.225, 70.825, 73.1499999999999, 71.925,  71.25, 73.625, 70.8, 70.1, 72.225, 70.65, 71.7999999999999, 72.25,  71.5, 70.3, 71.5, 72.5, 69.65, 69.1750000000001, 72.75), Y6 = c(615.6,  575.5, 615.4, 589.9, 606.4, 636.6, 551.55, 579.5, 589.4, 598.7,  470.15, 488.8, 512.5, 474.1, 500.75, 524.7, 504.9, 484.1, 497.25,  489), Y7 = c(335.539195565588, 359.834917608241, 335.575951966647,  357.790692959951, 333.286528104675, 353.588506032236, 364.366872182404,  366.16286093936, 351.99769389574, 352.409644879114, 302.158050528416,  314.464169350194, 278.31031721728, 313.875605554085, 279.951178433919,  300.141203224282, 308.802753249051, 292.681876126123, 308.529108917156,  317.955004237038)), row.names = c(NA, -20L), class = "data.frame")

现在,我进行主成分分析。

pca<- prcomp(df[, c(-1,-2)], scale = TRUE)

fviz_pca_biplot(pca, label = "var", col.var="Black",labelsize = 4, 
                arrowsize = 0.3, pointsize=2, repel = TRUE, habillage = df$SEASON,
                addEllipses = TRUE, palette = c("grey25", "grey65")) +
  labs(title="") +
  scale_x_continuous(breaks= seq(-4,4,1), limits = c(-4,4)) +
  theme_grey(base_size=16, base_family="serif")+
  theme(axis.line= element_line(size=0.5, colour="black"),
        axis.title.y= element_text (margin = margin(t=0, r=0, b=0, l=0)),
        legend.position = c(0.9,0.1),
        legend.title = element_blank(),
        legend.key = element_rect(color = "white", fill = "white"),
        legend.background= element_rect(fill= alpha("grey",.05)),
        plot.margin= margin(-0.5,0.5,0,0.3,"cm"))+
  windows(width=6, height=5.5)

这是 PCA 的图表。

现在我愿意

  1. 删除圆圈边框。
  2. 提供圆形透明颜色(即低 D 下蓝色透明度为 60%)。
  3. 将两组中的点形状更改为圆形(在低 D 时,现在是三角形)。

你能告诉我该怎么做吗?

非常感谢!!

r pca biplot
2个回答
2
投票

要更改椭圆的边界线,您可以使用

ggplot_build
并将线型更改为“空白”,如下所示:

library(factoextra)
library(ggplot2)
p <- fviz_pca_biplot(pca, label = "var", col.var="Black",labelsize = 4, 
                arrowsize = 0.3, pointsize=2, repel = TRUE, habillage = df$SEASON,
                addEllipses = TRUE, palette = c("grey25", "grey65")) +
  labs(title="") +
  scale_x_continuous(breaks= seq(-4,4,1), limits = c(-4,4)) +
  theme_grey(base_size=16, base_family="serif")+
  theme(axis.line= element_line(size=0.5, colour="black"),
        axis.title.y= element_text (margin = margin(t=0, r=0, b=0, l=0)),
        legend.position = c(0.9,0.1),
        legend.title = element_blank(),
        legend.key = element_rect(color = "white", fill = "white"),
        legend.background= element_rect(fill= alpha("grey",.05)),
        plot.margin= margin(-0.5,0.5,0,0.3,"cm"))

q <- ggplot_build(p)
q$data[[2]]$linetype = "blank"
q <- ggplot_gtable(q)
plot(q)

创建于 2022-09-10,使用 reprex v2.0.2


0
投票

使用“ellipse.border.remove”参数

fviz_pca_ind(res.pca,
              col.ind = treatment, # color by groups
              col.var = "steelblue",
              palette = col,
              mean.point = FALSE,
              addEllipses = TRUE, # Concentration ellipses
              pointsize=2,
              ellipse.type = "confidence",
              ellipse.alpha = 0.35,
              alpha.ind=1, 
              label=FALSE,
              repel = FALSE,
              show.legend=FALSE,
              ellipse.level = 0.95, # Lower confidence level
              legend.title = "Group",
              ellipse.border.remove = TRUE)

欲了解更多信息, https://github.com/kassambara/factoextra/blob/master/R/fviz_pca.R

© www.soinside.com 2019 - 2024. All rights reserved.