載入 R 套件
在使用 R 套件時,有兩個非常重要的函式:
install.packages(),顧名思義,用來安裝指定的套件。library()用來載入套件,讓它能在你的 R 工作環境中使用。
安裝套件需要系統管理員權限。這代表在 DataCamp 介面中,install.packages() 不會運作。不過,最熱門的 CRAN 套件已經安裝在我們的伺服器上。你可以用 library() 把它們載入。
本練習屬於課程
R 中級
練習說明
- 「載入」
ggplot2套件;確認你是在「載入」(而不是「安裝」)套件! - 執行
ggplot(mtcars, aes(wt, hp)) + geom_point()來建立簡單的散佈圖,並確認已可使用ggplot2。 - 最後,用
search()函式列出目前已載入到你工作環境中的套件。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Load the ggplot2 package
___("___")
# Use ggplot2 to create a scatter plot
___
# Check out the currently attached packages again
___()