ggplot中的绘图功能-参数列表 [英] Draw function in ggplot - list of parameters

查看:198
本文介绍了ggplot中的绘图功能-参数列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

功能图的简单示例:

p <- ggplot(data = data.frame(x = 0), mapping = aes(x = x))
p + stat_function(fun = function(x) x^2 + 1*2)

是否可以在ggplot中的绘图代码中添加参数列表? 像这样吗?

Is it possible to add a list of parameters inside the plot code in ggplot? Something like this?

fun1 <- function(x) x^2 + a*b
p <- ggplot(data = data.frame(x = 0), mapping = aes(x = x))
p + stat_function(fun = fun1, par=list(a=1, b=2)) + xlim(-5,5)

推荐答案

喜欢吗?

fun1 <- function(x,a,b) a*x^2 + b
p <- ggplot(data = data.frame(x = 0), mapping = aes(x = x))
p + 
  stat_function(fun = fun1, args=list(a=1, b=2)) + 
  stat_function(fun = fun1, args=list(a=2, b=1), col='red') + 
  xlim(-5,5)

这篇关于ggplot中的绘图功能-参数列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆