Creating a heatmap map with geom_tile from ggplot2 in R (CC258)

preview_player
Показать описание
Pat shares how to create a world-wide map of precipitation data as a heatmap using the geom_tile function from ggplot2. To generate the final figure he is plotting the z-score of monthly precipitation for each longitude and latitude relative to the precipitation over the past 30 days for each long and lat combination. The overall goal of this project is to highlight reproducible research practices using a number of tools including ggplot, geom_raster, geom_tile, scale_fill_gradient2, labs, theme, and more. The specific output from this project will be a map-based visual that shows the level of drought across the globe.

#geom_tile #Rstats #R

Support Riffomonas by becoming a Patreon member!

You can also find complete tutorials for learning R with the tidyverse using...

0:00 Introduction
2:44 Creating a heatmap with geom_tile
6:30 Modifying fill color gradient
10:16 Rescaling color gradient to increase contrast
13:51 Formatting and placing the legend
17:58 Saving and modifying appearance of visual
19:37 Adding dynamic titles
23:17 Updating snakefile and committing changes
Рекомендации по теме
Комментарии
Автор

Jeah! Finally a plot! :) thanks again for this amazing series!

svenr
Автор

I always learn so much from your videos. The best practice is the reproducibility

djangoworldwide
Автор

Hey Pat, I'm having a problem getting my dates in my CSVs to be read the same in R. It seems like the format is the same in the CSV file (I checked the date format two ways. First by Rt clicking the column and using format cell to put both CSVs in the same format. Second, formatted by clicking on Data in the top ribbon of excel and going to Text to Columns and verifying the column data format is the same.)
When I bind those dataframes the dates look different. The wrong one is being read this way: 8/11/2021 (DMY) 17:00, the good one looks like this: 2022-08-14 (YMD) 17:00.

Here's my code just in case it helps.

bind<-rbind(alt28, fortysix) %>%
%>%
separate(col=time, into =c("date", "time"), sep = " ")

dat<-bind %>%
mutate(year=year(date),
month=month(date),
day=day(date),
month=as.factor(month),
type=as.factor(type)) %>%
drop_na(month)

new<- dat %>%
select(dl, time, temp, type, year, month, day) %>%
mutate(month = factor(month,
levels=c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"),
labels = c("Jan", "Feb", "March", "April", "May", "June", "July", "Aug", "Sep", "Oct", "Nov", "Dec")))

By the time I get to my code called "new" the CSV with problems is reading year as day, month as month, and day as 20 (the first 2 numbers in the year 2021) (DMY). Yet, nothing I seem to do in the CSV files seem to make a difference. Please help!! I have a TON of CSV files and many of them have this problem.

Thanks!! Wish I could take a workshop with you. I run into problems like these all the time and stack overflow can't answer them all ;(

cristinacampbell
Автор

Maybe I missed it in one of your previous videos, but why did you switch from RStudio to VS Code?

Nloon
Автор

Excellent! A small change: you forgot to remove the ticks from the x-axis

PhilippusCesena