---
title: "temperature"
output: html_document
date: "`r Sys.Date()`"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(ggplot2)
data_file="temperature.csv"
dirout="PLOTS"
```
```{r funkcje}
save_plot <- function(plot, dirout, name_file, width, height){
name<-paste(dirout, name_file, sep='/')
ggsave(filename = paste(name, ".svg", sep=""), plot = plot, width = width, height = height, dpi = 300, bg = "transparent")
ggsave(filename = paste(name, ".pdf", sep=""), plot = plot, width = width, height = height, bg = "transparent")
ggsave(filename = paste(name, ".png", sep=""), plot = plot, width = width, height = height, dpi = 300, bg = "transparent")
}
make_plot <- function(data, dirout, name, width, height, tytul) {
plot <- ggplot(data, aes(x = day_of_year)) +
geom_ribbon(aes(ymin = Tmin, ymax = Tmax),
fill = "lightblue", alpha = 0.75) +
geom_line(aes(y = Tmean), color = "red", size = 1) +
scale_x_continuous(
breaks = seq(1, nrow(data), by = 1),
labels = data$label[seq(1, nrow(data), by = 1)]
) +
labs(title = tytul,
x = "Data (month.day)",
y = "Temperature (°C)") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 90, hjust = 1, size = 8))
save_plot(plot, dirout, name, width, height)
}
```
```{r plot, echo=FALSE}
data_df <- read.table(data_file, header = TRUE, sep = "\t")
# 2020
data_2020 <-data_df[data_df$year == 2020 &
((data_df$month == 4 & data_df$day >= 2) |
(data_df$month == 5) |
(data_df$month == 6 & data_df$day <= 23)), ]
data_2020$day_of_year <- 1:nrow(data_2020)
data_2020$label <- sprintf("%02d.%02d", data_2020$month, data_2020$day)
make_plot(data_2020, dirout, "temp_2020", 40, 5, "Temperature in 2020")
# 2021
data_2021 <- data_df[data_df$year == 2021 &
((data_df$month == 4 & data_df$day >= 2) |
(data_df$month == 5) |
(data_df$month == 6 & data_df$day <= 23)), ]
data_2021$day_of_year <- 1:nrow(data_2021)
data_2021$label <- sprintf("%02d.%02d", data_2021$month, data_2021$day)
make_plot(data_2021, dirout, "temp_2021", 40, 5, "Temperature in 2021")
```