2017-10-29 72 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)