r - seq.int(from, to, length.out = n) 中的错误:'from' 必须是一个有限的数字,任何人都可以帮助我吗?
问题描述
这是我的代码,我同时使用 ggplot2 和 reconplots:
library(ggplot2)
demanda<- function(q) (100-q/10)
oferta<- function(q) (q/4)
x_range <- 1:500
curve_intersection<- curve(demanda, oferta, empirical=FALSE,
domain=c(min(x_range),max(x_range)))
curve_intersection
ggplot() +
stat_function(aes(x_range)),color= "green",size=1,fun=demanda) +
stat_function(aes(x_range)),color= "red",size=1,fun=oferta) +
geom_vline(xintercept =curve_intersection$x,linetype= "doted" ) +
geom_hline(yintercept = curve_intersection$y,linetype="doted") +
theme_classic()
解决方案
我通过他们的GitHubreconPlots
对包进行了研究,这是我的解决方案
安装并加载包
library(devtools)
install_github("andrewheiss/reconPlots")
library(reconPlots)
我试图从他们的 GitHub 上学习这个例子,发现这个例子不起作用。所以我修复了一些代码,结果如下
library(ggplot2)
library(reconPlots)
demanda <- function(q) (100-q/10)
oferta <- function(q) (q/4)
x_range <- 1:500
curve_intersection <- curve_intersect(demanda, oferta, empirical=FALSE, domain=c(min(x_range),max(x_range)))
ggplot(data.frame(x_range), aes(x_range)) +
stat_function(color= "green", size=1, fun = demanda) +
stat_function(color= "red", size=1, fun = oferta) +
geom_vline(xintercept = curve_intersection$x, linetype = "dotted") +
geom_hline(yintercept = curve_intersection$y, linetype = "dotted") +
theme_classic()
请注意,该curve_intersect
函数来自reconPlots
包,它与Rcurve
中的包中的函数不同graphics
推荐阅读
- r - 从 R 包标准修改 `pr_curve` 和 `auc_curve` 的图形大小
- dialogflow-es - 我想创建两个意图,一个用于激活医生,第二个用于停用有问题的医生
- javascript - 如何根据选择值动态更改“onChange”属性值?
- vue.js - 如何防止或避免此错误“Uncaught TypeError: event.date.format is not a function”?
- python - 如何使用过滤器搜索特定的数据集
- hibernate - HTTPSession 自动关闭而关闭休眠会话
- javascript - 如何在本机反应中获取多个复选框值并更新到服务器
- angular - 为什么我的编辑表单不显示其数据?
- java - 无法实例化 @InjectMocks 字段
- amazon-web-services - AWS CloudFormation ContainerDefinitions Secrets 为每个变量分配完整的 SecretString