Created
July 17, 2022 10:23
-
-
Save cavedave/ef3502c93c492352d53b4875224f7110 to your computer and use it in GitHub Desktop.
Ridgeline plot (Joyplot) of temperatures at dublin Airport in 2021. Thicker means there were more days with that temperature. Using max temperature as thats how we think of it due to weather forecasts. As in yesterday was 21C means the hottest yesterday got was 21Cget data from https://www.met.ie/climate/available-data/historical-data for Dublin…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get data from https://www.met.ie/climate/available-data/historical-data | |
for Dublin airport | |
```{r} | |
dub<-read_csv('dly532.csv', skip=25, col_names = TRUE) | |
head(dub) | |
``` | |
date looks like 01-jan-1942 | |
separate it out into 3 columns | |
```{r} | |
dub = dub %>% separate("date", c('Day','Month','Year')) | |
head(dub) | |
``` | |
Pick on year | |
```{r} | |
lastY<-dub %>% filter(Year=='2021') | |
head(lastY) | |
``` | |
Capitalise the month names to look better and help the next transform | |
```{r} | |
library(R.utils) | |
lastY$Month<-capitalize(lastY$Month) | |
head(lastY) | |
``` | |
Month in normal January top of Y axis order | |
```{r} | |
#This NAs the column. Without the last block. Im guessing due to not capital starting letters | |
lastY$Month = factor(lastY$Month, levels = month.abb) | |
head(lastY) | |
``` | |
cast some variables to numbers | |
```{r} | |
lastY$Year <- as.numeric(lastY$Year) | |
lastY$Day <- as.numeric(lastY$Day) | |
head(lastY) | |
``` | |
```{r} | |
# Plot | |
p<-ggplot(lastY, aes(x = maxtp, y = Month, group=Month, fill = stat(x))) + | |
geom_density_ridges_gradient() + | |
scale_fill_gradientn(colors = rev(col_strip)) + | |
#scale_fill_viridis(name = "Temp", option = "C") + | |
scale_y_discrete(limits = rev(levels(lastY$Month)))+ | |
labs(title = 'Temperatures in Ireland in 2021') + | |
theme( | |
legend.position="none", | |
panel.spacing = unit(0.1, "lines"), | |
strip.text.x = element_text(size = 8) | |
) | |
p | |
``` | |
Clean up the graph a bit | |
```{r} | |
p <- p + theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(), | |
panel.grid.minor = element_blank(), axis.line = element_blank(),legend.position="none") | |
p | |
``` | |
```{r} | |
p<-p + labs(x=NULL, y=NULL) | |
p | |
``` | |
and title subtitle (my name) still missing | |
```{r} | |
#p<-p + ggtitle('Ireland Temperatures in 2021', subtitle = "Max temp each day Dublin Airport") | |
p <- p + labs(title = "Ireland Temperatures in 2021", | |
subtitle = "Max Temp each day Dublin Airport", | |
caption = "@iamreddave") | |
p<-p + theme(plot.title = element_text(size=22,hjust = 0.5)) | |
p | |
``` | |
```{r} | |
ggsave("Ireland2021.png") | |
``` |
Author
cavedave
commented
Jul 17, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment