Ridgeline plots in R with geom_ridgeline() and geom_density_ridges() [R- Graph Gallery Tutorial]

Поделиться
HTML-код
  • Опубликовано: 1 дек 2024

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

  • @TheDataDigest
    @TheDataDigest  2 месяца назад

    If you want to download the R code from this video you can do this here in my free skool community:
    www.skool.com/data-analysis-with-r-6607/classroom/daa88316?md=959f19346b794a0d8d5f22de14cd93f7

  • @floriansitte-kratzsch7355
    @floriansitte-kratzsch7355 3 года назад +4

    Nice and comprehensive overview!
    Gotta admit I definitely underrated ridge plots in my chart game so far...

    • @TheDataDigest
      @TheDataDigest  3 года назад +2

      Thanks a lot. Glad to hear I could teach you a new trick or two. There will be quite a few more R Gallery tutorials coming out this year.

  • @Muchael754
    @Muchael754 3 месяца назад +1

    Thank you for a wonderful tutorial!! Do you think I can use this package to create an actogram, vertically stacked bar plot?

    • @TheDataDigest
      @TheDataDigest  3 месяца назад

      That should be possible. If you google "actogram in R" you even find an "actogrammr" package that someone build in 2022. You can email me the image/chart you want to create and we can work on it together. Maybe it is enough to make a barchart and ridgeline plot separately and just join them with patchwork.

  • @3munchenman
    @3munchenman 2 года назад

    Helped me find the scale argument which i needed. thanks!

  • @AlexisMelo
    @AlexisMelo 2 года назад

    Gosh!
    You are great!
    Thanks a lot for such clear and informative video. I will be definitely be using those kind of plots.

    • @TheDataDigest
      @TheDataDigest  2 года назад +2

      Thanks Alexis! Nice comments like yours give me that extra boost and joy to keep going and make more videos :)

  • @Crass1000
    @Crass1000 5 месяцев назад

    Great example. Is it possible to include a median (or another) value in each plot instead of quantile?

    • @TheDataDigest
      @TheDataDigest  5 месяцев назад

      Can you give me a timestamp to the plot you are referring to? You can always add a line with "+ geom_vline(xintercept = median(data$column))". Or geom_hline(yintercept = ...) for horizontal lines.

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

    nice video but I can't seem to understand how I could create one single density curve graph and use the gradient fill color (I am a begginer)

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

      Hi there. Thanks for the question, it took me a while to figure it out myself.
      I found a solution for a single curve but it is a bit complicated. For the basic geom_density() function that one would use for a single variable there is no "geom_density_gradient()" function that can then be addressed with "gradient_fill".
      Can you try the following code and let me know if this is what you were looking for:
      library(ggplot2); library(magrittr) # or load the whole tidyverse package. Install packages if necessary.
      iris %>% ggplot(aes(x = Sepal.Width)) + geom_density(color = "red", fill = "yellow")
      # If you want to add gradient you need to go via the special ridges_gradient function again:
      library(ggridges)
      iris %>% ggplot(aes(x = Sepal.Width, y = Species, fill = stat(x))) + geom_density_ridges_gradient() + scale_fill_gradient(low = "green", high = "red")
      # If you want to only show one Species you can use the filter function:
      iris %>% filter(Species == "setosa") %>% ggplot(aes(x = Sepal.Width, y = Species, fill = stat(x))) + geom_density_ridges_gradient() + scale_fill_gradient(low = "green", high = "red")
      Hope that helped. If you have any more questions feel free to send your code to: question@thedatadigest.email

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

      @@TheDataDigest oo, thank you very much for your answer! I am busy today but I will try it other day!!

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

      @@GOATMENTATOR No problem, take your time. :) I am here if you have further questions.

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

      @@TheDataDigest Hi! Unfotunately I wasn't successful. Your sample worked great but with my data it didn't because I have only two columns in my data. I don't have anything to filter off as in your example (I don't have Y value). I tried to create arbitrary categories for y value so your method would work but it still didn't. I got the error: Elements must equal the number of rows or 1.
      Just to be sure creating basic density plot works fine with my data.

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

      @@GOATMENTATOR Feel free to email me your code and your data (or a sample of your data). You can also attach screenshot or images of what you want your final plot to look like. Maybe I can help this way.