Announcement

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

  • Bar graph with shading of parts of bars based on other variables

    Hello
    Is it possible to make a bar graph where some parts of the graph are shaded?


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(id end rec res)
    1  78   .   .
    2 169   .   .
    2   .  20  30
    2   .  80 140
    3 365   .   .
    3   .  60 200
    4 365   .   .
    4   .  20 120
    4   . 160 200
    5   .  10 300
    5 365   .   .
    6 365   .   .
    end

    Im generating the bargraph as a horizontal bar with length defined by the variable 'end' and I also have intervals within the bars defined by variables 'rec' and 'res'

    Code:
    tw (bar end id, hor bcolor(blue%20) lcolor(none) lwidth(vthin))(scatter id rec, mcolor(blue) msize(tiny) msymbol(square))(scatter id
    > res, mcolor(red) msize(tiny) msymbol(square)), ylabel(none) ymtick(none)

    Click image for larger version

Name:	stata.png
Views:	1
Size:	18.8 KB
ID:	1769195





    I want to shade the bar black or some other color between the blue and red markers on each bar like this (mockup in MS paint)

    Click image for larger version

Name:	stata2.png
Views:	1
Size:	18.1 KB
ID:	1769194



    Any help would be appreciated

    thanks!

    HP

  • #2
    Also, If its not possible to shade a bar like above, any ideas for how could do something visually similar
    tx!

    Comment


    • #3
      Code:
      tw bar end id, hor bcolor(blue%20) lcolor(none) lwidth(vthin) ///
      || rbar rec res id, hor bcolor(blue) ylabel(none) ymtick(none)

      Comment


      • #4
        perrfect!
        thanks!

        Comment

        Working...
        X