Skip to content

Instantly share code, notes, and snippets.

@juanchiem
Last active March 26, 2021 15:23
Show Gist options
  • Save juanchiem/e1f53f36fdd5f6c96f2ccddba8519d55 to your computer and use it in GitHub Desktop.
Save juanchiem/e1f53f36fdd5f6c96f2ccddba8519d55 to your computer and use it in GitHub Desktop.
library(zoo)
library(lubridate)
library(ggplot2)
set.seed(49)
dat1 = data.frame(date = seq(as.Date("2015-01-15"), as.Date("2015-12-15"), "1 month"),
value = cumsum(rnorm(12)))
dat1$date = as.yearmon(dat1$date)
dat2 = data.frame(date = seq(as.Date("2016-01-15"), as.Date("2016-12-15"), "1 month"),
value = cumsum(rnorm(12)))
dat2$date = as.yearmon(dat2$date)
ggplot(rbind(dat1,dat2),
aes(month(date, label=TRUE, abbr=TRUE),
value, group=factor(year(date)), colour=factor(year(date)))) +
geom_line() +
geom_point() +
labs(x="Month", colour="Year") +
theme_classic()
df <- tibble::tribble(
~fecha_de_siembra_dia_mes, ~variedad, ~rinde, ~campana,
"2021-06-15", "BAGUETTE_802", 6338.6, "17-18",
"2017-06-10", "BAGUETTE_802", 7518.3, "17-18",
"2017-06-13", "BAGUETTE_802", 6027, "17-18",
"2018-05-25", "BAGUETTE_802", 4400, "18-19",
"2018-06-10", "BAGUETTE_802", 5800, "18-19",
"2018-06-20", "BAGUETTE_802", 6250, "18-19",
"2019-06-04", "BAGUETTE_802", 4300, "19-20",
"2019-07-16", "BAGUETTE_501", 6500, "19-20",
"2019-06-10", "BAGUETTE_802", 6150, "19-20",
"2020-08-02", "BAGUETTE_501", 6100, "20-21",
"2020-07-20", "BAGUETTE_501", 6020, "20-21",
"2020-06-09", "BAGUETTE_802", 6751, "20-21"
)
df %>% mutate(
year = factor(year(as.Date(fecha_de_siembra_dia_mes))),
date = update(as.Date(fecha_de_siembra_dia_mes), year = 1)) %>%
ggplot(aes(date, rinde, col =year)) +
facet_grid(variedad~., scales="free_x")+
geom_point()
@juanchiem
Copy link
Author

image

@juanchiem
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment