我需要在每個月的 15 日從使用下面可重現的示例創建的 geom 線獲取值。原始幾何點位于不同的每月日期,具體取決于資料收集日期。感謝任何可能的幫助
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
uj5u.com熱心網友回復:
正如評論中所建議的,您可以approx在Value新日期:
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

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/444053.html
