去除PCA中椭圆的内部颜色
Removing the inner color of the ellipse in PCA
有谁知道如何更改椭圆中颜色的透明度(或 alpha)?
我只想保留情节中的边界线。
我试图模仿此站点中的代码:
http://www.sthda.com/english/wiki/fviz-pca-quick-principal-component-analysis-data-visualization-r-software-and-data-mining
但是我找不到关于椭圆颜色alpha值的选项。
#Dataset
require(ggplot2)
require(ggfortify)
require(factoextra)
set.seed(1)
df <- structure(list(Sample = c("cat", "dog", "rabbit", "chicken", "duck", "butterfly", "ladybug", "rose", "lily", "iris", "maple tree", "pinetree", "ginkgo"),
Class = c("mammalia", "mammalia", "mammalia", "bird", "bird", "insect", "insect", "flower", "flower", "flower", "tree", "tree", "tree"),
Kingdom = c("animalia", "animalia", "animalia", "animalia", "animalia", "animalia", "animalia", "plantae", "plantae", "plantae", "plantae", "plantae", "plantae")),
class = "data.frame", row.names = c(NA, -13L))
rownames(df)<-df[,1]
df[,1]<-NULL
for(i in 3:20){
df[,i]<-sample(100, size=nrow(df), replace=TRUE)
}
df[,c(3:20)]<-log(df[,c(3:20)]+1, base=2)
df #I ommitted the value from v13 to v20 for simplicity
Class Kingdom V3 V4 V5 V6 V7 V8 V9 V10 V11 V12
cat mammalia animalia 6.108524 5.781360 5.087463 5.357552 4.247928 5.614710 5.000000 5.129283 5.321928 6.303781
dog mammalia animalia 5.321928 6.228819 6.409391 5.491853 4.523562 6.491853 4.169925 3.459432 4.643856 4.523562
rabbit mammalia animalia 1.000000 3.000000 5.169925 4.700440 6.303781 4.584963 6.209453 1.000000 5.754888 6.149747
chicken bird animalia 5.129283 6.209453 6.149747 6.149747 6.044394 6.409391 6.459432 5.459432 6.539159 4.857981
duck bird animalia 6.459432 6.321928 6.228819 5.321928 6.149747 4.906891 6.392317 5.906891 6.442943 5.247928
butterfly insect animalia 5.459432 6.426265 5.426265 5.700440 6.459432 3.807355 6.507795 4.754888 5.357552 5.954196
ladybug insect animalia 3.906891 5.247928 5.285402 5.426265 6.149747 4.523562 5.614710 4.000000 6.614710 5.554589
rose flower plantae 6.375039 6.491853 4.392317 2.807355 6.247928 6.554589 6.022368 5.882643 6.392317 6.087463
lily flower plantae 5.906891 5.247928 4.857981 4.643856 6.357552 4.857981 6.569856 4.906891 6.507795 6.442943
iris flower plantae 5.700440 5.129283 4.392317 5.044394 6.658211 5.614710 6.599913 4.643856 5.169925 6.643856
maple tree tree plantae 6.614710 6.491853 5.491853 3.906891 3.807355 5.087463 5.930737 5.426265 5.459432 6.169925
pinetree tree plantae 6.426265 5.491853 6.459432 1.584963 5.357552 5.523562 5.700440 5.614710 1.000000 6.643856
ginkgo tree plantae 4.459432 6.321928 6.149747 5.523562 6.491853 4.459432 6.554589 6.266787 4.906891 5.700440
pca_df<-prcomp(df[,-c(1,2)], scale.=TRUE)
fviz_pca_ind(pca_df,
col.ind=df$Kingdom,
addEllipses = TRUE,
col.ind.sup=df$Kingdom,
repel=TRUE)
您可以使用可以找到 here.
的 ellipse.alpha
参数
fviz_pca_ind(pca_df,
col.ind=df$Kingdom,
addEllipses = TRUE,
col.ind.sup=df$Kingdom,
repel=TRUE, ellipse.alpha = 0)
(我忘了设置种子。抱歉...)
有谁知道如何更改椭圆中颜色的透明度(或 alpha)?
我只想保留情节中的边界线。
我试图模仿此站点中的代码:
http://www.sthda.com/english/wiki/fviz-pca-quick-principal-component-analysis-data-visualization-r-software-and-data-mining
但是我找不到关于椭圆颜色alpha值的选项。
#Dataset
require(ggplot2)
require(ggfortify)
require(factoextra)
set.seed(1)
df <- structure(list(Sample = c("cat", "dog", "rabbit", "chicken", "duck", "butterfly", "ladybug", "rose", "lily", "iris", "maple tree", "pinetree", "ginkgo"),
Class = c("mammalia", "mammalia", "mammalia", "bird", "bird", "insect", "insect", "flower", "flower", "flower", "tree", "tree", "tree"),
Kingdom = c("animalia", "animalia", "animalia", "animalia", "animalia", "animalia", "animalia", "plantae", "plantae", "plantae", "plantae", "plantae", "plantae")),
class = "data.frame", row.names = c(NA, -13L))
rownames(df)<-df[,1]
df[,1]<-NULL
for(i in 3:20){
df[,i]<-sample(100, size=nrow(df), replace=TRUE)
}
df[,c(3:20)]<-log(df[,c(3:20)]+1, base=2)
df #I ommitted the value from v13 to v20 for simplicity
Class Kingdom V3 V4 V5 V6 V7 V8 V9 V10 V11 V12
cat mammalia animalia 6.108524 5.781360 5.087463 5.357552 4.247928 5.614710 5.000000 5.129283 5.321928 6.303781
dog mammalia animalia 5.321928 6.228819 6.409391 5.491853 4.523562 6.491853 4.169925 3.459432 4.643856 4.523562
rabbit mammalia animalia 1.000000 3.000000 5.169925 4.700440 6.303781 4.584963 6.209453 1.000000 5.754888 6.149747
chicken bird animalia 5.129283 6.209453 6.149747 6.149747 6.044394 6.409391 6.459432 5.459432 6.539159 4.857981
duck bird animalia 6.459432 6.321928 6.228819 5.321928 6.149747 4.906891 6.392317 5.906891 6.442943 5.247928
butterfly insect animalia 5.459432 6.426265 5.426265 5.700440 6.459432 3.807355 6.507795 4.754888 5.357552 5.954196
ladybug insect animalia 3.906891 5.247928 5.285402 5.426265 6.149747 4.523562 5.614710 4.000000 6.614710 5.554589
rose flower plantae 6.375039 6.491853 4.392317 2.807355 6.247928 6.554589 6.022368 5.882643 6.392317 6.087463
lily flower plantae 5.906891 5.247928 4.857981 4.643856 6.357552 4.857981 6.569856 4.906891 6.507795 6.442943
iris flower plantae 5.700440 5.129283 4.392317 5.044394 6.658211 5.614710 6.599913 4.643856 5.169925 6.643856
maple tree tree plantae 6.614710 6.491853 5.491853 3.906891 3.807355 5.087463 5.930737 5.426265 5.459432 6.169925
pinetree tree plantae 6.426265 5.491853 6.459432 1.584963 5.357552 5.523562 5.700440 5.614710 1.000000 6.643856
ginkgo tree plantae 4.459432 6.321928 6.149747 5.523562 6.491853 4.459432 6.554589 6.266787 4.906891 5.700440
pca_df<-prcomp(df[,-c(1,2)], scale.=TRUE)
fviz_pca_ind(pca_df,
col.ind=df$Kingdom,
addEllipses = TRUE,
col.ind.sup=df$Kingdom,
repel=TRUE)
您可以使用可以找到 here.
的ellipse.alpha
参数
fviz_pca_ind(pca_df,
col.ind=df$Kingdom,
addEllipses = TRUE,
col.ind.sup=df$Kingdom,
repel=TRUE, ellipse.alpha = 0)
(我忘了设置种子。抱歉...)