r - 如何使用不一定经过每个点的 ggplot 将曲线拟合到我的数据中?
问题描述
我正在尝试将曲线拟合到 R 中的数据点,但 geom_smooth 只是在所有点上画了一条丑陋的线。我正在寻找一种方法来制作不一定经过所有点的平滑曲线。
这是我用来制作它的代码:
data <- data.frame(thickness = c(0.25, 0.50, 0.75, 1.00),
capacitance = c(1.844, 0.892, 0.586, 0.422))
ggplot(data, aes(x = thickness, y = capacitance)) +
geom_point() +
geom_smooth(method = "loess", se = F, formula = (y ~ (1/x)))
解决方案
在 geom_smooth 中平滑线的“黄土”方法有一个“跨度”参数,您可以使用它来实现此目的,例如
library(tidyverse)
data <- data.frame(thickness = c(0.25, 0.50, 0.75, 1.00),
capacitance = c(1.844, 0.892, 0.586, 0.422))
ggplot(data, aes(x = thickness, y = capacitance)) +
geom_point() +
geom_smooth(method = "loess", se = F,
formula = (y ~ (1/x)), span = 2)
由reprex 包于 2021-07-21 创建 (v2.0.0 )
有关更多详细信息,请参阅geom_smooth 中的 span 参数控制什么?
推荐阅读
- sql - 从包含查询的列中获取表的名称
- reactjs - 删除账号后重定向用户到首页 - express, mongo, axios
- c# - C# 控制台应用程序集合不包含对象类的定义并且没有可访问的扩展方法
- c - 什么是归并排序的基本操作以及如何在最佳情况下找到基本步骤的递归关系
- ios - 带有 M1 芯片的 Macmini 的 Xcode 抛出 arm64 架构错误
- swift - @Published 属性没有触发任何东西
- scala - 当两者都用相同的语言编写时,将功能程序的性能与其等效的非功能程序的性能进行比较是否有效?
- python-telegram-bot - 如何在 CallBackQueryHandler 中使用模式搜索字符串
- python - python 如何实现矩阵旋转功能
- python - 从具有任意数量尾随维度的 pytorch 中的张量获取矩阵