視覺化解釋變異
有了前面已經完成的計算,把資料用視覺化方式呈現會很有幫助。你現在要建立一個長條圖,顯示各主成分所解釋的變異量。
你在前一題建立的 variable_explained 向量已可使用,且 ggplot() 的 theme_() 已設為 classic。
本練習屬於課程
R 的特徵工程
練習說明
- 使用 PCA 的 tibble 中的資訊,建立一個顯示解釋變異的長條圖。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
PCA = tibble(PC = 1:length(sdev), var_explained = var_explained,
cumulative = cumsum(var_explained))
# Use the information in the PCA tibble to create a column plot of variance explained
PCA %>% ggplot(aes(x = ___, y = ___)) +
geom_col(fill = "steelblue") +
xlab("Principal components") +
ylab("Variance explained")