r - Adding a function curve to ggplot, not with geom_smooth()
问题描述
So I am trying to add my Bayesian logistic curve to the output I already have. For context, the coefficients of my output lead me to an equation of: y = -2.53 + .0003*x
Here is what I have tried, and I am getting the following error:
failed function, nothing ran for the function/line
And I do not want to use geom_smooth, as it does the following which is not the EXACT points that would be on the line. Help anybody?
解决方案
如果没有您的代码/数据或最小的可重现示例,很难为您的问题提供解决方案,但也许这种方法会对您有所帮助:
library(tidyverse)
#install.packages("gapminder")
library(gapminder)
gapminder %>%
mutate(is_long = ifelse(lifeExp > 80, 1, 0)) %>%
mutate(fit = (0.00003 * gdpPercap)^2 - .253) %>%
ggplot(aes(x = gdpPercap)) +
geom_jitter(aes(y = is_long), width = 0,
height = 0.01, alpha = 0.5) +
geom_line(aes(y = fit), colour = "blue", lty = 2) +
annotate("text", x = 50000, y = 0.5,
label = paste("y = -0.253 + .00003*x", "\U00B2", sep = "")) +
coord_cartesian(ylim = c(0,1))
推荐阅读
- jenkins - 如何触发脚本管道中的特定阶段?
- php - pdo 与类中的数据库断开连接
- amazon-web-services - AWS GP2 磁盘已满但显示可用?
- python - Python Pandas Group by Count Pivot of multiple column
- java - 如何解决 localhost 错误?
- laravel - 使用 guzzle http 发出发布请求时出错
- meta - Will adding a robots meta tag stop Google Analytics from tracking?
- perl - 有没有比 Perl 中的 Image::Compare 更快的比较图像的方法?
- java - 用更少的代码在 Java 中初始化变量的更好方法是什么?
- javascript - JSON 的分页导致 HTML/Javascript 页面