2
當試圖用ggplot
複製繪圖函數時遇到問題。我有兩個功能,定義如下:用ggplot2繪製「倒V」函數
GetMse <- function(x) 1 - max(x, 1 - x)
GetGini <- function(x) 2 * x * (1 - x)
使用默認R中繪製系統圖中看起來像:
現在用ggplot
出現問題:在圖紅色功能1是繪製爲直線上的圖2
任何IDE一個還是指針?下面粘貼ggplot
代碼。
library(ggplot2)
ggplot(data = data.frame(x = c(0.00001, 0.99999)), aes(x)) +
stat_function(fun = GetGini, geom = "line") +
stat_function(fun = GetMse, geom = "line", colour = "red")