Variability Plot in R

Designing of date-time variability plot in R. For example I used the data table of meteorological observation on some Ukrainian station. The exampled data table for this.

###DOWNLOADING THE DATA TABLE###
bigmeteo2<- read.csv("bigmeteo2.csv", headers=TRUE, sep=";", dec=".")

Code for converting data and graphical design:

###DOWNLOADING THE PACKAGES###
library(dplyr)
library(scales)
library(ggplot2)
library(lubridate)
###OPENING THE GRAPHICAL DEVICE###
png("air_temperature.png", width = 300, height = 200, units = "mm", res = 150)
###DOWNLOADING THE DATA TABLE INTO "PIPE"###
tbl_df(bigmeteo2) %>%
###CONVERTING AND FILTERING DATA###
mutate(date.posix = parse_date_time(date2, "%Y-%m-%d %H:%M:%S", tz = "Europe/Kiev"), time.tmp = as.POSIXct(format(date.posix, "%H:%M:%S"), format = "%H:%M:%S", tz = "Europe/Kiev")) %>%
filter(! is.na(T), punkt %in% c("Баштанка", "Лозоватка", "Бобринець"), date.posix <= "2014-12-31 23:30:00", date.posix >= "2014-11-01 00:00:00") %>%
###OPENING THE GGPLOT2 GRAPHICAL FUNCTION###
ggplot()+
geom_boxplot(aes(x = time.tmp, y = T, group = time.tmp, fill = punkt))+
facet_wrap(~punkt, ncol = 3)+
scale_x_datetime(breaks = date_breaks("2 hour"), minor_breaks = date_breaks("30 min"), labels = date_format("%H:%M", tz = "Europe/Kiev"))+
geom_hline(aes(yintercept = -5.0,  colour = "darkred"), linetype="dashed", size = 1.4)+#line on -5.0 degrees Celsius
geom_hline(aes(yintercept = 7.5,  colour = "darkred"), linetype="dashed", size = 1.4)+#line on 7.5 degrees Celsius
labs(y = "Air Temperature, °C", x = "Times of Day", title = "A Time Variability of Air Temperature")+
###TYPOGRAPNIC DESIGN OUR DIAGRAM###
theme(text = element_text(family = "Lieration Serif", face = "italic", size = 16, colour = "orangered4", lineheight = 0.8), legend.position = "bottom", legend.text = element_text(family = "Liberation Serif", face = "italic", size = 10, colour = "orangered4", lineheight = 0.8), axis.text.x = element_text(colour = "gray15", face="bold", size= 10, angle = 270, vjust = 0.5, hjust = 1), axis.text.y = element_text(colour = "gray15", face="bold", size= 10, angle = 0, vjust = 0.5, hjust = 1), axis.ticks = element_line(colour = "orange", size = 0.2), plot.background = element_rect(fill = "gray95"), panel.grid.major = element_line(colour = "orange", size = 0.2), panel.grid.minor = element_line(colour = "gray90"), panel.background=element_rect(fill="gray95"))+
guides(fill = FALSE)#print without guide ("legend")
###CLOSING THE GRAPHICAL DEVICE###
dev.off() 

The resulting plot:

A Time Variability of Air Temperature

A Time Variability of Air Temperature

Donate: WebMoney – Z237214434315, U396004717050 or R337925998765; PrivatBank – 5167982301844061

Leave a Comment

%d блогерам подобається це: