Announcement

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

  • Assigning different colors to each grouping variable in bar chart

    Hi,

    I'm trying to make a bar chart within several subgroups of variables (grouping variables) and I want to assign a colour for each of these grouping variables. I've tried manually changing this in graph editor, but each time i change a specific bar color, all the other bars change to the same color too.

    My variables:

    Time - Range of values
    Sex - Male, Female, Unknown
    Age Group - assigned group numbers - 1,2,3..

    My Stata Command:

    "graph bar (median) Time, over(Sex) over(Agegroup)"

    Awaiting your response.

    Many thanks

    J

  • #2
    As far as your syntax is concerned you're plotting one variable Time and the over() options don't affect that. But the incantation asyvars solves all.

    We don't have a data example from you, but you can run these commands to get an idea of technique.

    Code:
    sysuse auto, clear
    graph hbar (median) mpg, over(foreign) over(rep78) nofill
    graph hbar (median) mpg, over(foreign) over(rep78) nofill asyvars
    graph hbar (median) mpg, over(rep78) over(foreign) nofill asyvars
    graph hbar (median) mpg, over(foreign) over(rep78) nofill asyvars bar(1, color(blue)) bar(2, color(red))
    The use of graph hbar is immaterial to your question, except that here, and perhaps for your data too, its choice means that axis labels are more easily readable.

    Comment


    • #3
      This solved it! Thank you so much for the help!!

      Comment

      Working...
      X