Announcement

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

  • twoway bar option over() not allowed

    Hello,

    I am trying to combine a clustered-type bar chart with a scatter plot (I know it's an odd combination but is needed).
    I can create the two separately as I want with:-

    Code:
    region    basevalue    result1    result2    result3
    1    1527.4535    1.3188448    5.8728838    1.696458
    2    1019.9913    -10.977878    -2.34566    -1.2905247
    3    139.53406    1.6148564    5.7460833    2.0168254
    4    50.777878    1.500506    2.4120405    1.4608511
    5    11.730878    1.4280396    5.5639558    .85804629

    Code:
    graph bar result1 result2 result3, over(region)
    scatter basevalue region
    But when I try to combine the two, I am not able to get the bar as clusters. The option over() is apparently not allowed with twoway:-
    Code:
    twoway (bar result1 result2 result3, over(region)) (scatter basevalue region)
    This one works, but the bars are stacked, which I don't want
    Code:
    twoway (bar result1 result2 result3 region) (scatter basevalue region)
    Is there a work around? Would appreciate any help! I'm new to making graphing with stata.
    Last edited by Wajiha Csky; 25 Sep 2019, 21:08.

  • #2
    graph bar and twoway bar are very far apart. They are really quite separate commands.

    You have the last graph slightly wrong. The bars are superimposed, not stacked.

    But you can hardly tell as the values for the bar variables are much much smaller than the largest values for the scatter variable.

    This seems closer to what you are asking for but I can't believe it is what you really want. I could make guesses about what you want or suggestions about what you need, but it is better that you do so.

    Code:
    clear 
    input region    basevalue    result1    result2    result3
    1    1527.4535    1.3188448    5.8728838    1.696458
    2    1019.9913    -10.977878    -2.34566    -1.2905247
    3    139.53406    1.6148564    5.7460833    2.0168254
    4    50.777878    1.500506    2.4120405    1.4608511
    5    11.730878    1.4280396    5.5639558    .85804629
    end 
    
    * offsets left and right 
    gen region_l = region - 0.2 
    gen region_r = region + 0.2 
    
    set scheme s1color 
    
    twoway bar result1 region_l, barw(0.2) bcolor(orange) ///
    ||     bar result2 region, barw(0.2)   bcolor(black)  ///
    ||     bar result3 region_r, barw(0.2) bcolor(blue)   /// 
    ||     scatter basevalue region

    Click image for larger version

Name:	csky.png
Views:	1
Size:	23.0 KB
ID:	1517983

    Comment

    Working...
    X