Plot a function with ggplot, equivalent of curve()

前端 未结 2 1618
一整个雨季
一整个雨季 2020-11-28 05:01

Is there an equivalent method for plotting functions using ggplot to the curve() command employed in base graphics? I guess that the alternative wo

2条回答
  •  旧巷少年郎
    2020-11-28 05:24

    The data.frame example above works well, and it makes grid lines. The qplot example doesn't work in ggplot2 2.2.0 for the reasons given.

    You can also use the "curve" function in ggplot2 2.2.0, but it does not automatically make grid lines or background color. For example:

    curve(cos(x), from= 0, to= pi/2).  
    

    The "ggplot(data.frame(... ) method gives the full impressive range of ggplot2's formatting options. I like it.

提交回复
热议问题