自訂 gapminder 顯示
來用按國家繪製的壽命期望軌跡圖,實際測試這些功能。請注意,我們仍然只使用大洋洲的兩個國家。
本練習屬於課程
使用 R 的 Trelliscope 視覺化巨量資料
練習說明
- 加上
geom_smooth()圖層,並使用"lm"方法加入線性模型擬合。 - 將座標軸尺度設為
"sliced"。 - 在圖中加入線性模型圖層後,指定要為此顯示自動計算 cognostics,並探索這個圖層為顯示新增了哪些新的 cognostics。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
library(trelliscopejs)
library(ggplot2)
# Create the plot
ggplot(gapminder, aes(year, lifeExp)) +
geom_point() +
geom_smooth(method = ___, se = FALSE) +
facet_trelliscope(~ country + continent,
name = "lifeExp_by_country",
desc = "Life expectancy vs. year for 142 countries.",
nrow = 1, ncol = 2,
# Set the scales
scales = ___,
# Specify automatic cognistics
auto_cog = ___)