在月中获取 geom_line 不均等分布值 geom_points
Obtaining geom_line values at mid-month for unequally spread geom_points
我需要在每个月的 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
如评论中所建议,您可以 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
我需要在每个月的 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
如评论中所建议,您可以 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