Announcement

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

  • Shripada Rao
    started a topic color of box plots

    color of box plots

    Hi, I created two box plots for the birth weight of infants based on two interventions during pregnancy (interventions 1 and 2). Both box plots have the same color. How do we make them have different colors? For example blue color for intervention 1 and red color for intervention 2. Thank you for the advice.
    Attached Files

  • Shripada Rao
    replied
    Thank you, very useful information

    Leave a comment:


  • Nick Cox
    replied
    Do please read the help on graph box. The options you need (not functions) are documented. They work with Alan's method too.

    Code:
    . sysuse auto, clear
    (1978 Automobile Data)
    
    . separate mpg, by(foreign) veryshortlabel
    
                  storage   display    value
    variable name   type    format     label      variable label
    ---------------------------------------------------------------------------------------------------------------------------------------------------------
    mpg0            byte    %8.0g                 Domestic
    mpg1            byte    %8.0g                 Foreign
    
    . graph box mpg?
    
    . graph box mpg? , box(1, color(red)) box(2, color(blue))
    
    . graph box mpg, over(foreign) asyvars
    
    . graph box mpg, over(foreign) asyvars box(1, color(red)) box(2, color(blue))
    
    . graph box mpg, over(foreign) asyvars box(1, color(red)) box(2, color(blue)) marker(1, mc(red)) marker(2, mc(blue))
    
    .

    Leave a comment:


  • Shripada Rao
    replied
    Thank you Nick, it was very useful. Is there a function in the edit graph section where we could choose different colors of our choice for such graphs? Alan, when I tried your method, both graphs changed to a similar color.

    Leave a comment:


  • Alan Neustadtl
    replied
    You can also use the asyvars option like this:
    Code:
    sysuse auto
    graph box mpg, over(foreign) asyvar

    Leave a comment:


  • Nick Cox
    replied
    That said, your dataset contains 21 observations only, so you might as well as use a dotplot or strip plot to show all the details in the data.

    Leave a comment:


  • Nick Cox
    replied
    Please don't expect people to open .dta attachments. This is explained in FAQ Advice #12. https://www.statalist.org/forums/help#stata

    This code example gives a hint on one solution.

    Code:
    sysuse auto, clear
    set scheme s1color
    graph box mpg, over(foreign)
    separate mpg, by(foreign) veryshortlabel
    graph box mpg?

    Leave a comment:

Working...
X