Announcement

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

  • Using twoway histogram to plot bar graphs

    Hello,

    I would like to plot two variables in overlaid bars that have the same 7 categories (pre_occupqual1 and pre_occupqual2) by subgroup (camp). So far I have only been able to do it with twoway histogram. My code is:
    Code:
    twoway histogram pre_occupqual1, by(camp) discrete color(gray) ///
     ||  histogram pre_occupqual2, by(camp) discrete fcolor(none) lcolor(black) ///
     legend( order(1 "Camp occupations" 2 "Pre-camp occupations"))
    This is the closest version with twoway histogram. Ideally, I would have code numbers and a second legend to describe each category below as the labels are too long:
    Click image for larger version

Name:	wra_occupations.png
Views:	1
Size:	74.4 KB
ID:	1479052

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(pre_occupqual1 pre_occupqual2) str15 camp
    . . "Gila River"    
    . . "Tule Lake"     
    . . "Tule Lake"     
    . . "Tule Lake"     
    4 . "Gila River"    
    3 . "Tule Lake"     
    2 . "Tule Lake"     
    . . "Rohwer"        
    3 4 "Gila River"    
    . . "Tule Lake"     
    4 . "Tule Lake"     
    . . "Gila River"    
    . . "Tule Lake"     
    . . "Tule Lake"     
    4 . "Tule Lake"     
    . . "Rohwer"        
    4 . "Tule Lake"     
    . . "Tule Lake"     
    . . "Gila River"    
    . . "Tule Lake"     
    . . "Tule Lake"     
    . . "Rohwer"        
    . . "Tule Lake"     
    4 6 "Tule Lake"     
    4 6 "Tule Lake"     
    4 3 "Tule Lake"     
    . . "Gila River"    
    2 . "Topaz"         
    . . "Heart Mountain"
    . . "Tule Lake"     
    3 4 "Tule Lake"     
    . . "Tule Lake"     
    . . "Rohwer"        
    7 . "Heart Mountain"
    . . "Rohwer"        
    . . "Tule Lake"     
    . . "Tule Lake"     
    . . "Tule Lake"     
    3 6 "Tule Lake"     
    4 2 "Gila River"    
    . . "Rohwer"        
    . . "Tule Lake"     
    . . "Rohwer"        
    4 . "Tule Lake"     
    4 4 "Tule Lake"     
    . . "Tule Lake"     
    . . "Heart Mountain"
    . . "Tule Lake"     
    . . "Tule Lake"     
    2 . "Rohwer"        
    . . "Tule Lake"     
    3 . "Tule Lake"     
    3 . "Heart Mountain"
    2 5 "Tule Lake"     
    5 . "Tule Lake"     
    2 . "Rohwer"        
    . . "Tule Lake"     
    . . "Tule Lake"     
    . . "Gila River"    
    3 4 "Heart Mountain"
    4 . "Topaz"         
    . . "Tule Lake"     
    6 4 "Rohwer"        
    4 . "Tule Lake"     
    5 . "Tule Lake"     
    . . "Tule Lake"     
    2 . "Tule Lake"     
    . . "Gila River"    
    4 . "Tule Lake"     
    1 . "Tule Lake"     
    4 . "Topaz"         
    . . "Rohwer"        
    . . "Tule Lake"     
    3 . "Tule Lake"     
    4 6 "Tule Lake"     
    4 4 "Tule Lake"     
    2 7 "Tule Lake"     
    . . "Rohwer"        
    . . "Rohwer"        
    2 1 "Tule Lake"     
    . . "Tule Lake"     
    6 4 "Gila River"    
    4 5 "Tule Lake"     
    3 . "Gila River"    
    4 3 "Tule Lake"     
    4 . "Heart Mountain"
    4 . "Gila River"    
    4 . "Heart Mountain"
    . . "Tule Lake"     
    4 6 "Amache"        
    . . "Tule Lake"     
    4 . "Rohwer"        
    4 6 "Tule Lake"     
    5 . "Tule Lake"     
    4 . "Tule Lake"     
    4 4 "Tule Lake"     
    3 . "Tule Lake"     
    3 . "Gila River"    
    4 . "Rohwer"        
    2 4 "Gila River"    
    end
    label values pre_occupqual1 occ_label
    label values pre_occupqual2 occ_label
    label def occ_label 1 "Professional or managerial", modify
    label def occ_label 2 "Clerical, sales", modify
    label def occ_label 3 "Service", modify
    label def occ_label 4 "Agricultural, fishery & forestry", modify
    label def occ_label 5 "Skilled", modify
    label def occ_label 6 "Semiskilled", modify
    label def occ_label 7 "Unskilled", modify

  • #2
    If you spell out xla(1/7) as an extra option you will get part of the way. I don't think you have much space to show the labels too unless you abbreviate mightily. A density scale doesn't make much obvious sense for a categorical variable. I would not use touching bars for this kind of data.

    Comment


    • #3
      thanks

      Comment


      • #4
        If you go

        Code:
        contract pre_occupqual1 pre_occupqual2 camp
        dataex
        and show the results, then you may get better advice on plotting. (For some reason, much of your data example is missing on both qualification variables.)


        Comment


        • #5
          Also interestingly, I am not able to have the total as a "subgroup".

          With:
          Code:
          twoway histogram pre_occupqual1,  by(camp, total)  discrete  color(gray) xla(1/7) gap(10) ///
           ||  histogram pre_occupqual2,  by(camp, total) discrete  gap(10) fcolor(none) lcolor(black) xla(1/7) ///
           legend( order(1 "Camp occupations" 2 "Pre-camp occupations"))
          It gives me: "option total not allowed". When it is actually an example in the help file oh twoway histogram
          Code:
          * Example generated by -dataex-. To install: ssc install dataex
          clear
          input str15 camp float(pre_occupqual1 pre_occupqual2) int _freq
          "Amache"         1 1  89
          "Gila River"     1 1 208
          "Heart Mountain" 1 1 193
          "Jerome"         1 1  85
          "Manzanar"       1 1 103
          "Minidoka"       1 1 144
          "Poston"         1 1 105
          "Rohwer"         1 1 102
          "Topaz"          1 1 114
          "Tule Lake"      1 1 103
          "Amache"         1 2  93
          "Gila River"     1 2 198
          "Heart Mountain" 1 2 118
          "Jerome"         1 2 141
          "Manzanar"       1 2 163
          "Minidoka"       1 2 117
          "Poston"         1 2  80
          "Rohwer"         1 2  86
          "Topaz"          1 2  96
          "Tule Lake"      1 2 122
          "Amache"         1 3  21
          "Gila River"     1 3 169
          "Heart Mountain" 1 3 165
          "Jerome"         1 3  64
          "Manzanar"       1 3  73
          "Minidoka"       1 3 153
          "Poston"         1 3  46
          "Rohwer"         1 3  62
          "Topaz"          1 3  78
          "Tule Lake"      1 3 105
          "Amache"         1 4  52
          "Gila River"     1 4 243
          "Heart Mountain" 1 4 118
          "Jerome"         1 4  91
          "Manzanar"       1 4 119
          "Minidoka"       1 4  75
          "Poston"         1 4  92
          "Rohwer"         1 4 113
          "Topaz"          1 4  41
          "Tule Lake"      1 4 161
          "Amache"         1 5  20
          "Gila River"     1 5 105
          "Heart Mountain" 1 5  76
          "Jerome"         1 5  40
          "Manzanar"       1 5  43
          "Minidoka"       1 5  64
          "Poston"         1 5  40
          "Rohwer"         1 5  31
          "Topaz"          1 5  38
          "Tule Lake"      1 5  95
          "Amache"         1 6  16
          "Gila River"     1 6  61
          "Heart Mountain" 1 6  46
          "Jerome"         1 6  18
          "Manzanar"       1 6  37
          "Minidoka"       1 6  90
          "Poston"         1 6  53
          "Rohwer"         1 6  31
          "Topaz"          1 6  38
          "Tule Lake"      1 6  66
          "Amache"         1 7   2
          "Gila River"     1 7   7
          "Heart Mountain" 1 7   7
          "Manzanar"       1 7  13
          "Minidoka"       1 7  52
          "Poston"         1 7   1
          "Rohwer"         1 7   6
          "Topaz"          1 7  11
          "Tule Lake"      1 7  20
          "Amache"         1 . 271
          "Gila River"     1 . 863
          "Heart Mountain" 1 . 679
          "Jerome"         1 . 323
          "Manzanar"       1 . 410
          "Minidoka"       1 . 572
          "Poston"         1 . 772
          "Rohwer"         1 . 396
          "Topaz"          1 . 541
          "Tule Lake"      1 . 345
          "Amache"         2 1  55
          "Gila River"     2 1 164
          "Heart Mountain" 2 1 115
          "Jerome"         2 1  55
          "Manzanar"       2 1 116
          "Minidoka"       2 1  74
          "Poston"         2 1  90
          "Rohwer"         2 1  49
          "Topaz"          2 1  79
          "Tule Lake"      2 1  82
          "Amache"         2 2 131
          "Gila River"     2 2 210
          "Heart Mountain" 2 2 147
          "Jerome"         2 2  85
          "Manzanar"       2 2 117
          "Minidoka"       2 2 153
          "Poston"         2 2 111
          "Rohwer"         2 2  85
          "Topaz"          2 2 123
          "Tule Lake"      2 2 176
          "Amache"         2 3  73
          end
          label values pre_occupqual1 occ_label
          label values pre_occupqual2 occ_label
          label def occ_label 1 "Professional or managerial", modify
          label def occ_label 2 "Clerical, sales", modify
          label def occ_label 3 "Service", modify
          label def occ_label 4 "Agricultural, fishery & forestry", modify
          label def occ_label 5 "Skilled", modify
          label def occ_label 6 "Semiskilled", modify
          label def occ_label 7 "Unskilled", modify

          Comment

          Working...
          X