2017-10-29 74 views
0

說我有這樣的功能:GGPLOT2 - 在函數圖變化線寬

quad <- function(x) 
{ 
    return (x^2) 
} 

那我繪製使用ggplot

plot <- ggplot(data.frame(x=c(0,4)), aes(x = x)) + 
     stat_function(fun = quad) 

到目前爲止,一切都很好,但該行是真的瘦了。因此,我添加一些特定的幾何形狀的線:

plot + geom_line(size=2) 

但它返回此錯誤:

Error: geom_line requires the following missing aesthetics: y

如何操作線幾何在這種類型的圖表?

+0

您需要'stat_function(fun = quad,size = 2)'。 –

回答

1

打了一段時間後,我發現名爲size的參數可以傳入stat_function。它與gem_line具有相同的效果:

plot <- ggplot(data.frame(x=c(0,4)), aes(x = x)) + 
     stat_function(fun = quad, size=1.5)