Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can I use -grstyle- to set more than one color for twoway histograms?

    Hi,

    I've been fiddling around with the grstyle command to make my own scheme. In this process I've stumbled upon an issue when trying to make a twoway histogram.

    I want to cycle through colors automatically when showing distributions for different groups in a twoway histogram. I tried to set the colors using "grstyle color p1 *color*" and so forth, but this doesn't work on histograms apparently. It does work on other graph types though.

    For histograms you need to specifically set the color of the histogram using "grstyle color histogram *color*". But I can't figure out how to add another color other than emerald to the grstyle command. Does anyone know?

    Please refrain from trying to make sense of the figures, this question purely relates to the color issue.

    Thanks!

    Code:
    sysuse auto, clear
    
    *hist and twoway line
    grstyle init
    grstyle color p1 emerald
    grstyle color p2 lavender
    
    hist mpg // no color change
    graph twoway (hist mpg) (hist trunk) // no color change
    
    line mpg price // color change
    graph twoway (line mpg price) (line trunk price) // color change for both
    
    grstyle clear
    
    *twoway hist
    grstyle init
    grstyle color histogram emerald
    
    hist mpg // color change
    graph twoway (hist mpg) (hist trunk) // color change, but both emerald

  • #2
    You cant. By default Histogram uses a single color scheme.
    a work around would be:

    Code:
     
     graph twoway (hist mpg, pstyle(p1) ) (hist trunk, pstyle(p2))

    Comment

    Working...
    X