r - 如何将更高和相等的子句分配给函数,而不会得到真假结果?输入
问题描述
library(ggplot2)
p <- ggplot(data = data.frame(x = 0), mapping = aes(x = x))
fun.1 <- function(x) 1000*x+3000*y
fun.1 >=300000* **#this clause gives me error; if instead y run:strong text*
*fun.1 <- function(x) 1000*x+3000*y )>=300000,*
**then I get true or false*
p + stat_function(fun = fun.1) + xlim(0,300)
解决方案
第一部分建议是将您的功能更改为:
y = function(x) 1000 / 3000 * x
这个函数很容易解决,也简化了我们的逻辑。由于这很简单,我们也可以通过基本数学求解这个函数何时超过 300,000。
thresh = 300000
x_min = thresh / (1000 / 3000)
x_min
## [1] 9e+05
最后,我们可以更改绘图调用以将x_min
用作 的一部分xlim
:
library(ggplot2)
p <- ggplot(data = data.frame(x = 0), mapping = aes(x = x))
p + stat_function(fun = y) + xlim(x_min,x_min + 300)
推荐阅读
- spring-boot - Spring Boot 安全性 - 允许使用过期 JWT 令牌的用户请求
- android - 使用 Jetpack Compose Navigation 导航到另一个 Composable 后记住 List State 的最佳实践
- django - 导航栏未正确显示
- python - Python接受的套接字连接未关闭
- r - R:对矩阵进行排序,使高值沿主对角线并向外变小
- java - Maven 无法使用 gitlab 解决依赖关系
- f# - 专家 f# 脚本编译异常
- intellij-idea - 将多个参数参数传递给 Intellij 上的主类时出错
- bigbluebutton - 9+小时的录音
- angular - Angular - *ngIf 不评估