Page 1 of 1
theme colors
Posted: Wed Sep 01, 2021 7:46 am
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.
Re: theme colors
Posted: Wed Sep 01, 2021 8:33 am
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
Re: theme colors
Posted: Wed Sep 01, 2021 8:44 am
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
Re: theme colors
Posted: Wed Sep 01, 2021 9:44 am
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.
Re: theme colors
Posted: Wed Sep 01, 2021 11:29 am
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.
Re: theme colors
Posted: Sun Sep 05, 2021 9:48 am
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
Re: theme colors
Posted: Tue Sep 07, 2021 12:26 pm
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")