r - 我可以将曲线趋势线添加到每列只有一个数据点的 ggplot 吗?
问题描述
我使用 ggplot2 为土壤水分释放曲线创建了折线图。但是,因为我在每个压力值(x 轴)上只有一个数据点,所以这些线直接从点到点连接。我想保留这些点,但有一条曲线可以显示点的趋势。这是土壤水分释放曲线的典型样式。
数据:
> dput(head(sub2018))
structure(list(Year = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label =
c("2018",
"2019"), class = "factor"), Pressure = structure(1:6, .Label = c("-1",
"-0.5", "-0.25", "-0.2", "-0.1", "-0.05", "-0.02", "-0.01", "0"
), class = "factor"), meanVWC = c(0.291819594, 0.308328767666667,
0.318496127666667, 0.323671866333333, 0.349356212666667,
0.374201803666667
)), row.names = c(NA, -6L), class = c("grouped_df", "tbl_df",
"tbl", "data.frame"), vars = "Year", drop = TRUE, indices = list(
0:5), group_sizes = 6L, biggest_group_size = 6L, labels = structure(list(
Year = structure(1L, .Label = c("2018", "2019"), class = "factor")),
row.names = c(NA,
-1L), class = "data.frame", vars = "Year", drop = TRUE))
格图:
GGplot2018 <- ggplot(sub2018, aes(x=Pressure, y=meanVWC, group=1)) +
geom_line() +
geom_point() + labs(y= "Volumetric Water Content")
GGplot2018
有谁知道我是否/如何添加这条曲线?
非常感谢您的帮助!
解决方案
我相信这就是您正在寻找的:
GGplot2018 <- ggplot(sub2018, aes(x=Pressure, y=meanVWC, group=1)) +
geom_line()+
geom_point() + labs(y= "Volumetric Water Content")+
geom_smooth(method = "lm",se = FALSE)
GGplot2018
推荐阅读
- angular - 无法在 Angular 中获取先前检查的表单值
- html - 如何在重定向到其他页面之前显示消息?
- ios - 无法在 iOS 设备上打开 pkpass
- python - 如何模拟同一类的嵌套函数调用
- r - 格点图未显示 R 中 y 值的计数
- ios - 如何有效地用流内容填充 UITextView?
- haskell - (Num a) vs (Eq a)
- apache-flink - Flink:如何在同一个 TaskManager 上为不同的作业拥有单独的日志文件和日志配置?
- java - 从 BitBucket 克隆 Eclipse 项目会导致意外的代码错误
- javascript - 如何使用 AD 用户凭据使用 .ajax 调用访问跨域站点 (SharePoint)