benjann / violinplot

Stata module to draw violin plots
MIT License
11 stars 1 forks source link

STATA vioplot colors option is not allowed #6

Open chunlai425 opened 7 months ago

chunlai425 commented 7 months ago

Hi, I would like to change the color of each violin. I have tried : vioplot variantA, over(variantB) vertical colors(plasma) It said "option colors() not allowed"

Any solution?

Thanks

benjann commented 6 months ago

Hi, your code should work, but the command is violinplot, not vioplot. ben

chunlai425 commented 6 months ago

Thank you! That works. Now, I would like to plot the data points in each violin and change the color of the data points per group. I used: violinplot variant, over(group) vertical colors(plasma) fill nomedian nobox nowhiskers rag(spread(5) msymbol(o) mcolor(blue%50))

All the data points are the same color, blue.

Is it possible to change the color for data points per each group?

Thank you

benjann commented 6 months ago

It is. By default, option colors() affects both the colors of the violins and the colors of the data points. Example:

sysuse nlsw88
violinplot wage, over(race) vertical fill nomedian nobox nowhiskers ///
    rag(spread(5) msymbol(o)) ///
    colors(plasma)

Use option ragcolors() you want different colors for the data points. Examples:

violinplot wage, over(race) vertical fill nomedian nobox nowhiskers ///
    rag(spread(5) msymbol(o)) ///
    colors(plasma, intensity(.5)) ragcolors(plasma)
violinplot wage, over(race) vertical fill nomedian nobox nowhiskers ///
    rag(spread(5) msymbol(o)) ///
    colors(plasma) ragcolors(carto sunset)

ben

chunlai425 commented 6 months ago

Thank you so much! It works