Announcement

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

  • Graph bar with a grading palette of colors

    Hi there,

    I am trying to picture a bar graph. However, instead of randomly selected colours I would like to colour the bars with a colour scale, for example, I would like the bars to go gradually from light red to dark red. Below I leave you the picture I got so far and the code I am using:

    Code:
    graph hbar valueVAFC if nsector==7 & inrange(time,2012,2018),     ///
        over(time,gap(0) lab(labsize(vsmall)))                         ///
        over(size, gap(100) lab(labsize(small)))                     ///
        ytitle("Value added at factor costs")                        ///
        yscale(titlegap(5))                                         ///
        asyvars                                                     ///
        nolab                                                         ///
        legend(rows(1) symysize(2) symxsize(5) size(2))
    I would appreciate if sb could come up with an easy answer.

    KR

    Click image for larger version

Name:	Graph.png
Views:	1
Size:	43.6 KB
ID:	1638244

  • #2
    Code:
    webuse grunfeld, clear
    keep if company==1 & year<1942
    forval i=1/7{
        local colors "`colors' bar(`i', color(red*`=(`i'/7)'))"
    }
    gr hbar invest, over(year) asyvars leg(off) scheme(s1color) showyvars ytitle("") `colors'
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	33.5 KB
ID:	1638345

    Comment


    • #3
      Andrew Musau gave a good answer but I would strongly commend a line chart as much simpler and more effective.

      Comment


      • #4
        If you install -colorpalette- (a part of palettes packages which can be installed from SSC) written by Ben Jann , you can combine it with Andrew Musau's codes in #2:

        Code:
        webuse grunfeld, clear
        keep if company==1 & year<1942
        
        colorpalette hsv, reds
        forval i=1/7 {
            local colors "`colors' bar(`i', color(`r(p`i')'))"
        }
        
        graph hbar invest, over(year) asyvars leg(off) scheme(s1color) showyvars ytitle("") `colors'
        Click image for larger version

Name:	Graph2.png
Views:	1
Size:	40.1 KB
ID:	1638354

        Comment


        • #5
          Hi, many thanks for your replies, they worked perfectly!!!

          Comment

          Working...
          X