在R中绘制最小值、最大值函数

在R中绘制最小值、最大值函数,r,function,ggplot2,R,Function,Ggplot2,我在绘制最小、最大函数时遇到困难 1/(最小值(最大值(c*x+d,1/a),1/b)) 库(ggplot2) target我想问题是函数使用了max和min,而不是pmax和pmin # Loading the package library(ggplot2) # Defining the parameters target <- data.frame(year = c(2011), a = c(29.82), b = c(22.27),c = c(0.0004546), d=c(0

我在绘制最小、最大函数时遇到困难
1/(最小值(最大值(c*x+d,1/a),1/b))

库(ggplot2)

target我想问题是函数使用了max和min,而不是pmax和pmin

# Loading the package
library(ggplot2)

# Defining the parameters
target <- data.frame(year = c(2011), a = c(29.82),  b = c(22.27),c = c(0.0004546), d=c(0.014900))

# Defining the function
eqs = function(x){1/(pmin(pmax(target[1,4]*x+target[1,5],1/target[1,2]),1/target[1,3]))}

# COnstructing the data frame
df <- data.frame(x=c(0,10,20,30,40,50,55,60,70, 100))

# Ploting the curve
ggplot(df, aes(df$x)) + stat_function(fun = eqs) + xlab("x") + ylab("y")
#加载包
图书馆(GG2)
#定义参数

target您需要使函数正确(目前缺少一个逗号),并通过
args
参数将
m
作为(命名)列表传递给
tatu函数。@RomanLuštrik:这没有帮助。到目前为止您尝试了什么,结果在哪里?顺便说一句:你的问题有几个拼写错误。请看我在原始帖子中的修改。到目前为止,我只得到一条水平线。有人知道如何解决这个问题吗?
# Loading the package
library(ggplot2)

# Defining the parameters
target <- data.frame(year = c(2011), a = c(29.82),  b = c(22.27),c = c(0.0004546), d=c(0.014900))

# Defining the function
eqs = function(x){1/(pmin(pmax(target[1,4]*x+target[1,5],1/target[1,2]),1/target[1,3]))}

# COnstructing the data frame
df <- data.frame(x=c(0,10,20,30,40,50,55,60,70, 100))

# Ploting the curve
ggplot(df, aes(df$x)) + stat_function(fun = eqs) + xlab("x") + ylab("y")