跳轉到內容

R 程式設計/圖形語法

來自華夏公益教科書,開放的書籍,開放的世界

Hadley Wickham 開發了 **ggplot2**,一個根據 *圖形語法* 原則設計的圖形庫。

繪製函式

[編輯 | 編輯原始碼]

我們使用 qplot() 以及選項 stat=function 

# Plot the quadratic function
square <- function(x){
  x^2
}
mode(square)
qplot(c(0, 2), stat = "function", fun = square, geom = "line")

以下是使用正弦函式的另一個示例 

# plot the sinus functon
qplot(c(-10, 10), stat = "function", fun = sin, geom = "line")

參考文獻

[編輯 | 編輯原始碼]
  • 萊蘭·威爾金森,圖形語法(統計與計算),施普林格出版社,2005
  • 哈德利·威克漢姆,ggplot2:資料分析的優雅圖形,用R!,施普林格出版社,2009
華夏公益教科書