-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSolution_Scatterplot.R
More file actions
35 lines (34 loc) · 1.22 KB
/
Copy pathSolution_Scatterplot.R
File metadata and controls
35 lines (34 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
library(tidyverse)
library(knitr)
# read csv data, Note: Semicolon seperated CSVs can be loaded by function 'read_delim()'
airquality <- read_delim("data/AirQualityUpperAut.csv", delim = ";")
# half-hourly temperature measurement of station S108 to data frame
temp_tab <- airquality %>%
dplyr::filter(component == "TEMP" & meantype == "HMW" & station == "S108")
# half-hourly relative humidity measurement of station S108 to data frame
humidity_tab <- airquality %>%
dplyr::filter(component == "RF" & meantype == "HMW" & station == "S108")
# join humidity and temperature tables by common field 'time'
temp_tab %>%
dplyr::inner_join(
# right table
humidity_tab,
# columns to match
by = c("time" = "time")
) %>%
dplyr::select(time, value.x, value.y) %>% # select relevant columns from joined table
# create plot
ggplot2::ggplot(
.,
aes(
x = value.x,
y = value.y
)
) +
labs(
x = "air temperature [°C]",
y = "relative humidity [%]"
) +
ggplot2::geom_point(color = "blue") + # define geometry scatterplot, with point color blue
ggplot2::geom_smooth(method = lm, color = "red", fill = "#69b3a2", se = TRUE) + # with linear trend and confidence interval
ggplot2::theme_minimal()