Announcement

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

  • Bar graph color by over group

    Hello. I have a question regarding bar graph settings.

    I found a way to set different colors for each bar by executing the code below.

    Code:
    sysuse auto, clear
    graph bar price, over(foreign, sort(order) descending) ///
        asyvars bar(1, color(blue)) bar(2, color(red)) ///
        title("Auto") ytitle("") graphregion(color(white))
    However, the result of the above code is not what I want. The desired appearance is like the attached image below, where the bars are not stuck, and there is no legend.

    Click image for larger version

Name:	2023-11-27 215850.png
Views:	1
Size:	10.4 KB
ID:	1735237
    I've modified many graphs through the recording button in the graph editor, but I would like to know the code that I want to get the above image.

    I appreciate your advice.

    Thank you.

  • #2
    Code:
    sysuse auto, clear
    graph bar price, over(foreign, sort(order) gap(40) descending) ///
        asyvars bar(1, color(blue)) bar(2, color(red)) ///
        title("Auto") ytitle("") graphregion(color(white)) ///
        showyvars leg(off) 

    Comment


    • #3
      Andrew Musau Thank you so much! It is the perfect answer that I want!

      Comment

      Working...
      X