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
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.
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.
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
@@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.
@@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.
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
Nice and comprehensive overview!
Gotta admit I definitely underrated ridge plots in my chart game so far...
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.
Thank you for a wonderful tutorial!! Do you think I can use this package to create an actogram, vertically stacked bar plot?
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.
Helped me find the scale argument which i needed. thanks!
Gosh!
You are great!
Thanks a lot for such clear and informative video. I will be definitely be using those kind of plots.
Thanks Alexis! Nice comments like yours give me that extra boost and joy to keep going and make more videos :)
Great example. Is it possible to include a median (or another) value in each plot instead of quantile?
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.
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)
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
@@TheDataDigest oo, thank you very much for your answer! I am busy today but I will try it other day!!
@@GOATMENTATOR No problem, take your time. :) I am here if you have further questions.
@@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.
@@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.