【发布时间】:2020-12-14 02:25:41
【问题描述】:
我有以下data.frame,其中我有多个变量,我想使用ggplot 绘制。我了解如果使用Date 而不拆分为Year、Month 和Day 将获得line plot,但我想知道,如何使用Year 列可以让我获得line plot?
library(tidyverse)
library(lubridate)
set.seed(123)
DF <- data.frame(Date = seq(as.Date("2011-01-01"), to = as.Date("2014-12-31"), by = "day"),
F = runif(1461,20,60), D = runif(1461,30,70)) %>%
separate(Date, into = c("Year", "Month", "Day"))
ggplot(DF, aes(x = Year))+
geom_line(aes(y = F)) +
geom_line(aes(y = D))
【问题讨论】:
-
我尝试了
x = as.numeric(Year)和as.integer(Year)而ggploting但没有成功。
标签: r ggplot2 plot tidyverse lubridate