theme colors

Everything related to the development of modules in jamovi
Post Reply
jacotaco
Posts: 4
Joined: Wed Sep 01, 2021 7:31 am

theme colors

Post by jacotaco »

Hey there!
I'm currently working on a Jamovi Module for school students for my Mathmatics teaching studies. As I want to do a plot, comparing several binomial distributions I wonder how I can access the current jamovi theme colors if I want to have more than one.
Does anybody know ?
So far I know that I can access the color in the plot function with ``theme$fill[2]`` but this is only one color.
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: theme colors

Post by jonathon »

take a look here:

https://github.com/jamovi/jmv/blob/master/R/descriptives.b.R#L858-L899

the plot functions take a theme object, and a ggtheme object. if you're using ggplot, you can usually just + the ggtheme onto the plot object

cheers

jonathon
jacotaco
Posts: 4
Joined: Wed Sep 01, 2021 7:31 am

Re: theme colors

Post by jacotaco »

Thanks for the quick reply!
I already looked at the code of descriptives. What I'm looking for is getting the same colours as when splitting a histogram (blue, grey, yellow in default settings).

Code: Select all

plot <- ggplot(data, aes(x=var)) +
                ylab("P(X=r)") + 
                xlab("r") +
                xlim(0,100)+
                ylim(0,0.3)+
                ggtheme[[1]] +
                geom_bar(aes(y=density),stat="identity",linetype="blank",alpha=0.7,fill = theme$fill[2]) +
                geom_bar(aes(y=density2),stat="identity",linetype="blank",alpha=0.7,fill = theme$fill[2] ) 
I did use the ggtheme but it has no effect on the fill color so far. I just didn't find how the ggtheme or the theme that are passed to the plot function are constituted.

Cheers
jacotaco
Posts: 4
Joined: Wed Sep 01, 2021 7:31 am

Re: theme colors

Post by jacotaco »

ok I found a workaround by pasting the two densities in one list and giving them different groups. Then you can use fill=group in ggplot.
User avatar
Ravi
Posts: 194
Joined: Sat Jan 28, 2017 11:18 am

Re: theme colors

Post by Ravi »

That's indeed how you have to do it to make use of the ggtheme. ggplot needs to know on which grouping you want to base the color/fill.
jacotaco
Posts: 4
Joined: Wed Sep 01, 2021 7:31 am

Re: theme colors

Post by jacotaco »

ok for anyone having the same problem, I found out at stack overflow how to get fill colors from the ggplot build object: https://stackoverflow.com/questions/11774262/how-to-extract-the-fill-colours-from-a-ggplot-object
User avatar
Ravi
Posts: 194
Joined: Sat Jan 28, 2017 11:18 am

Re: theme colors

Post by Ravi »

The name of the palette is also accessible through theme$palette which you can pass on to the jmvcore::colorPalette function as follows (where n is the number of colors you want, and type whether you want the fill or color palette):

Code: Select all

jmvcore::colorPalette(n=2, theme$palette, type="fill")
Post Reply