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

แชร์
ฝัง
  • เผยแพร่เมื่อ 24 ก.ค. 2024
  • 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.
    You can find my blog post for this episode at www.riffomonas.org/code_club/....
    #geom_tile #Rstats #R
    Support Riffomonas by becoming a Patreon member!
    / riffomonas
    Want more practice on the concepts covered in Code Club? You can sign up for my weekly newsletter at shop.riffomonas.org/youtube to get practice problems, tips, and insights.
    If you're interested in taking an upcoming 3 day R workshop be sure to check out our schedule at riffomonas.org/workshops/
    You can also find complete tutorials for learning R with the tidyverse using...
    Microbial ecology data: www.riffomonas.org/minimalR/
    General data: www.riffomonas.org/generalR/
    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
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 12

  • @sven9r
    @sven9r ปีที่แล้ว +1

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

    • @Riffomonas
      @Riffomonas  ปีที่แล้ว

      Hah! Thanks for watching, I'm glad you enjoy the videos - I'm learning a lot too!

  • @djangoworldwide7925
    @djangoworldwide7925 ปีที่แล้ว +1

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

    • @Riffomonas
      @Riffomonas  ปีที่แล้ว

      Thanks! I appreciate your continued watching 🤓

  • @PhilippusCesena
    @PhilippusCesena ปีที่แล้ว +1

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

    • @Riffomonas
      @Riffomonas  ปีที่แล้ว

      Oh my! You're right 🤓 I'll have to come back and get those in a future episode

  • @N1loon
    @N1loon ปีที่แล้ว +1

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

    • @Riffomonas
      @Riffomonas  ปีที่แล้ว +3

      Thanks for asking! This project is being done with conda to keep track of software and libraries and snakemake to keep track of dependencies. I find that those are a lot easier to work with outside of RStudio. Also, this project is a good example of how you might interact with tools on a high performance computer that doesn't allow a GUI interface like would be required for RStudio.

    • @N1loon
      @N1loon ปีที่แล้ว

      @@Riffomonas Interesting! Thanks for clarifying :)

  • @cristinacampbell7372
    @cristinacampbell7372 ปีที่แล้ว +1

    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%
    mutate(time=as.character(time)) %>%
    separate(col=time, into =c("date", "time"), sep = " ")
    dat%
    mutate(year=year(date),
    month=month(date),
    day=day(date),
    month=as.factor(month),
    type=as.factor(type)) %>%
    drop_na(month)
    new%
    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 ;(

    • @cristinacampbell7372
      @cristinacampbell7372 ปีที่แล้ว +1

      NM Pat just figured it out. I need to go to custom and get the data into a YYYY/M/D h:mm:ss. Wow! That took a good several hours to realize I had a big problem with my data to finding this simple solution. At least it's solved.

    • @Riffomonas
      @Riffomonas  ปีที่แล้ว

      Wonderful - glad you got it figured out ☺