在月中获取不均匀分布的 geom_points 的 geom_line 值

发布于 2025-01-14 02:12:43 字数 956 浏览 2 评论 0原文

我需要在每月 15 日从使用下面的可重现示例创建的几何线中获取值。原始几何点的每月日期取决于数据收集日。感谢任何可能的帮助在此处输入图像描述

Value <- c(19.14104, 11.72115, 9.66083, 10.99109, 13.65047, 10.10627, 13.53027, 18.25272, 25.57741)
Dates <- c("07/11/19", "28/11/19", "16/12/19", "10/01/20", "21/01/20", "03/02/20", "04/03/20", "19/03/20", "20/05/20")

df <- data.frame(Value, Dates)
View(df)

df$Dates <- lubridate::dmy(df$Dates)


gpp_plot <- ggplot() + 
  geom_point(data = df, aes(x=Dates, y=Value), alpha=0.5) +
  geom_line(data = df, aes(x=Dates, y=Value), alpha=0.5) +
  theme(axis.text.y=element_text(size=10),
        axis.title=element_text(size=10, , face = "bold"),
        axis.text.x = element_text(size=10, face = "bold", angle = 45, vjust = 0.5))+
  xlab('') +
  ylab('LI-7810_FCH4_DRY_[nmol+1m-2s-1]') +
  scale_x_date(date_labels = "%b %y",breaks = "1 months") +
  theme(legend.position="none")
gpp_plot

I need to obtain value at 15th of every month from the geom line created using the reproducible example below. The original geom points are at varied monthly dates depending on data collection days. Appreciate any help possibleenter image description here

Value <- c(19.14104, 11.72115, 9.66083, 10.99109, 13.65047, 10.10627, 13.53027, 18.25272, 25.57741)
Dates <- c("07/11/19", "28/11/19", "16/12/19", "10/01/20", "21/01/20", "03/02/20", "04/03/20", "19/03/20", "20/05/20")

df <- data.frame(Value, Dates)
View(df)

df$Dates <- lubridate::dmy(df$Dates)


gpp_plot <- ggplot() + 
  geom_point(data = df, aes(x=Dates, y=Value), alpha=0.5) +
  geom_line(data = df, aes(x=Dates, y=Value), alpha=0.5) +
  theme(axis.text.y=element_text(size=10),
        axis.title=element_text(size=10, , face = "bold"),
        axis.text.x = element_text(size=10, face = "bold", angle = 45, vjust = 0.5))+
  xlab('') +
  ylab('LI-7810_FCH4_DRY_[nmol+1m-2s-1]') +
  scale_x_date(date_labels = "%b %y",breaks = "1 months") +
  theme(legend.position="none")
gpp_plot

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苹果你个爱泡泡 2025-01-21 02:12:43

正如评论中所建议的,您可以近似新日期的

library(ggplot2)
library(lubridate)

Dates <- dmy(Dates)

NewDates <- seq(floor_date(min(Dates),'month'),floor_date(max(Dates),'month'),by='month')+days(14)

#[1] "2019-11-15" "2019-12-15" "2020-01-15" "2020-02-15" "2020-03-15" "2020-04-15" "2020-05-15"

NewValue <- approx(Dates,Value,NewDates)$y

df <- data.frame(Value=c(Value,NewValue), Dates=c(Dates,NewDates))


gpp_plot <- ggplot() + 
  geom_point(data = df, aes(x=Dates, y=Value), alpha=0.5) +
  geom_line(data = df, aes(x=Dates, y=Value), alpha=0.5) +
  theme(axis.text.y=element_text(size=10),
        axis.title=element_text(size=10, , face = "bold"),
        axis.text.x = element_text(size=10, face = "bold", angle = 45, vjust = 0.5))+
  scale_x_date(date_labels = "%b %y",breaks = "1 months") +
  ylab('LI-7810_FCH4_DRY_[nmol+1m-2s-1]') +

  theme(legend.position="none")
gpp_plot

As suggested in comments, you could approx the Value at new dates:

library(ggplot2)
library(lubridate)

Dates <- dmy(Dates)

NewDates <- seq(floor_date(min(Dates),'month'),floor_date(max(Dates),'month'),by='month')+days(14)

#[1] "2019-11-15" "2019-12-15" "2020-01-15" "2020-02-15" "2020-03-15" "2020-04-15" "2020-05-15"

NewValue <- approx(Dates,Value,NewDates)$y

df <- data.frame(Value=c(Value,NewValue), Dates=c(Dates,NewDates))


gpp_plot <- ggplot() + 
  geom_point(data = df, aes(x=Dates, y=Value), alpha=0.5) +
  geom_line(data = df, aes(x=Dates, y=Value), alpha=0.5) +
  theme(axis.text.y=element_text(size=10),
        axis.title=element_text(size=10, , face = "bold"),
        axis.text.x = element_text(size=10, face = "bold", angle = 45, vjust = 0.5))+
  scale_x_date(date_labels = "%b %y",breaks = "1 months") +
  ylab('LI-7810_FCH4_DRY_[nmol+1m-2s-1]') +

  theme(legend.position="none")
gpp_plot

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文