Using lubridate and ggplot2 to work with dates in R (CC234)

Поделиться
HTML-код
  • Опубликовано: 14 июл 2024
  • The lubridate R package has a number of tools for working with dates and the ggplot2 R package has functions to plot data along a date-based axis. In this episode, Pat uses these tools to plot the cumulative precipitation over the year to find whether this year is wetter or drier than previous years. We'll do everything within RStudio.
    You can find my blog post for this episode at www.riffomonas.org/code_club/....
    #ggplot2 #dplyr #R #Rstudio #Rstats
    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:40 Calculating the cumulative precipitation amount for each year
    6:56 Plotting cumulative precipitation
    9:21 Highlighting data from 2022
    12:53 Setting breaks and labels for x-axis
    16:31 Adjusting the theming of the figure
    17:05 Formatting y-axis
    19:30 Adding smoothed line through data
    21:09 Adding and formatting the title
  • НаукаНаука

Комментарии • 27

  • @Riffomonas
    @Riffomonas  Год назад +4

    Something I forgot to mention in the video was that at the end I ran renv::snapshot() to update my renv project with ggtext as a dependency.

  • @luisacuna1729
    @luisacuna1729 Год назад +3

    This tutorial is not only the best video for know how to use lubridate and ggplot, its a masterpice of how to creat great plots-

    • @Riffomonas
      @Riffomonas  Год назад +1

      Thanks Luis! That is very kind of you to say 🤓 thanks for watching

  • @PaoloCondo
    @PaoloCondo Год назад

    Thank you so much for your amazing videos. I hope our comments help the algorithm put your videos on top!

  • @TrentTube
    @TrentTube Год назад

    Fantastic. Thanks for your content!

  • @whalerman2689
    @whalerman2689 Год назад

    You are the best! It was very fun and useful, as always!

  • @AliMBaba-do2sl
    @AliMBaba-do2sl Год назад +1

    Extra ordinary... Great job!

  • @brianwood9610
    @brianwood9610 Год назад +2

    Another great episode. What would be very cool to do is take this data and try and forecast precipitation using an arima time series model. Thats prob going to be a few videos.

    • @Riffomonas
      @Riffomonas  Год назад

      Hah! I might need to produce another video… 🤓

    • @brianwood9610
      @brianwood9610 Год назад

      @@Riffomonas happy to jump in and help hahaha

  • @tekalegn_amanuel_1
    @tekalegn_amanuel_1 Год назад +1

    Everything is cool! Thanks!

  • @haoxu7437
    @haoxu7437 6 месяцев назад

    a smart move with the "glue" function and create the fake year '2022'

  • @PhilippusCesena
    @PhilippusCesena Год назад +1

    Thank you!

  • @haraldurkarlsson1147
    @haraldurkarlsson1147 Год назад

    Nice presentation. It takes quite a bit of work to tidy up the plot in the end. As I have mentioned earlier I have data from another station here in the upper midwest. However, the station stopped operating in 2005 so I used 2004 as my reference year. The data streches back to 1984 and what I see is actually is that the first six month are if anything drier. Note we are dealing with precipation but have happens if we include snow for the winter months?
    I did mention in a previous message that I has missing tmax data in the early 1900 and it looked quite serious. However, when I inspected the original data with the skimr and vizdat packages I found in fact that only 1 year was missing all the data - not just tmax. It might be a good idea to check the data for "missingness" before diving into extended analysis. That was the lesson I learned.
    Finally, some on mention that a video/exercise on time series analysis might be fun. I agree. By the way there is an interesting pacakge for dealing with time in R called padr. It might be worth looking at.
    Thanks.

    • @Riffomonas
      @Riffomonas  Год назад

      They convert snow into precipitation equivalents by melting it. Make sure you saw my note in the video that what I initially had removed all of the February data

    • @haraldurkarlsson1147
      @haraldurkarlsson1147 Год назад

      Makes sense. The term precipitation is the broad term.

  • @jjsantosjj1
    @jjsantosjj1 Год назад

    Thank you very much!! One question, do you know how to have different date_formats depending on the date? I mean: you have a timeseries which is hourly but I want to show in the x-axis for example: "17/05/2023", "06:00", "12:00", "18:00", "21:00", "18/05/2023", "06:00"... and so on

  • @caseyj1144
    @caseyj1144 Год назад +1

    My local data has other years with big gaps in it. If I wanted to check for complete years (every month represented at least 1 time in the year) I would use a window function in sql -- do you know a good way to query this in R? The closest thing I can think of is to use some sort of summarize len(year) and then make an assumption that I should have at least 300 datapoints/year, otherwise drop it

    • @Riffomonas
      @Riffomonas  Год назад

      I’d do group_by, mutate and filter

  • @djangoworldwide7925
    @djangoworldwide7925 Год назад +1

    Friday being the 6th day is a Jewish plot! Ita called using the jewish:: package 😅

  • @sven9r
    @sven9r Год назад +1

    Since you didn't want to hard code certain things in the title one could do this for the blue text as well:
    value_today

    • @Riffomonas
      @Riffomonas  Год назад

      Yes! I was thinking about this too 🤓