Histogram density graph

General help and assistance with jamovi. Bug reports can be made at our issues page: https://github.com/jamovi/jamovi/issues . (If you're unsure feel free to discuss it here)
Post Reply
carlosferreira
Posts: 4
Joined: Tue Feb 11, 2025 5:56 pm

Histogram density graph

Post by carlosferreira »

Recently when I make histograms with the density option, some of the density curves overlap. Is that a bug? It previously didn't happen in the same files.
Attachments
Jamovi histogram.png
Jamovi histogram.png (19.19 KiB) Viewed 14165 times
User avatar
reason180
Posts: 329
Joined: Mon Jul 24, 2017 4:56 pm

Re: Histogram density graph

Post by reason180 »

Are you saying that the exact same data, but with an older version of jamovi, yields non-overlapping curves?
carlosferreira
Posts: 4
Joined: Tue Feb 11, 2025 5:56 pm

Re: Histogram density graph

Post by carlosferreira »

I'm saying that at the end of last yaer it did not happen to me, and now all cases seem to have a significantly weird overlap. Does it has something to do with the size of the sample?
User avatar
jonathon
Posts: 2792
Joined: Fri Jan 27, 2017 10:04 am

Re: Histogram density graph

Post by jonathon »

you could attach a .omv file of those analyses here (you may need to zip it up first), and we'll see if there's something we might want to tweak here. it is quite unusual looking data, so we may or may not want to intervene here.

jonathon
carlosferreira
Posts: 4
Joined: Tue Feb 11, 2025 5:56 pm

Re: Histogram density graph

Post by carlosferreira »

Please find attached an example of it (while setting the example, I have noticed that if I change the order of the variables, the "bug" on the densities changes a bit, but still overlaps in most cases).
Attachments
Histogram bug.omv
(388.52 KiB) Downloaded 386 times
User avatar
Ravi
Posts: 199
Joined: Sat Jan 28, 2017 11:18 am

Re: Histogram density graph

Post by Ravi »

It's strange that it previously didn't happen with the same file, as the library that we're using to make these plots (ggrides) hasn't changed in over a year. I looked into the issue and it indeed has to do with groups having 2 or fewer data points. However, I looked into the issue and it seems that there is an easy fix to the alignment issue:

Code: Select all

library(ggplot2)
library(ggridges)

set.seed(1337)

df <- data.frame(
    dep = rnorm(40),
    group = sample(
        LETTERS[1:5], 
        40, 
        replace = TRUE, 
        prob = c(0.05, 0.25, 0.05, 0.6, 0.05)
    )
)

# How jamovi currently generates the plot
plot_old <- ggplot(data=df, aes(x=dep, y=group, fill=group)) + 
    geom_density_ridges(stat="binline", bins=18, scale=0.9) +
    geom_density_ridges(scale=0.9, alpha=0.4)

# How jamovi would generate the plot with the fix
plot_new <- ggplot(data=df, aes(x=dep, y=group, fill=group, height = after_stat(density))) + 
    geom_density_ridges(stat="binline", bins=18, scale=0.9) +
    geom_density_ridges(scale=0.9, alpha=0.4, stat="density")
I made a pull request to incorporate this fix into jamovi: www.github.com/jamovi/jmv/pull/426
User avatar
jonathon
Posts: 2792
Joined: Fri Jan 27, 2017 10:04 am

Re: Histogram density graph

Post by jonathon »

i've pushed out the 2.6.25 which includes this fix.

cheers

jonathon
carlosferreira
Posts: 4
Joined: Tue Feb 11, 2025 5:56 pm

Re: Histogram density graph

Post by carlosferreira »

I would like to thank the jamovi team for their prompt help and solution
Post Reply