Announcement

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

  • Name bar on Graph bar with more variable depicted.

    Goodmorning, I have the following dataset, I want to create a graph with a specific

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int Year str36 Countryoforigin float(tot_demand_c rec_over_tot newgra)
    2019 "United States of America"                  5 .005346221 91
    2019 "Liechtenstein"                             5 .005346221 91
    2019 "Tajikistan"                               10 .005346221 89
    2019 "Paraguay"                                 10 .005346221 89
    2019 "South Africa"                             15 .010692443 87
    2019 "Mexico"                                   15 .016038664 87
    2019 "South Sudan"                              20 .010692443 85
    2019 "Chile"                                    20 .010692443 85
    2019 "Cabo Verde"                               22 .005346221 84
    2019 "Argentina"                                23 .013900176 83
    2019 "Viet Nam"                                 25 .005346221 81
    2019 "Guatemala"                                25 .021384886 81
    2019 "Madagascar"                               35 .010692443 80
    2019 "Mauritius"                                36 .011761687 79
    2019 "United Rep. of Tanzania"                  40 .005346221 77
    2019 "Burundi"                                  40 .005346221 77
    2019 "Kazakhstan"                               61  .03314657 76
    2019 "Bolivia (Plurinational State of)"         63  .02459262 75
    2019 "Jordan"                                   68 .010692443 74
    2019 "Rwanda"                                   83 .010692443 73
    2019 "Gabon"                                    85 .005346221 72
    2019 "Dominican Rep."                           92  .04170053 71
    2019 "Zimbabwe"                                 98 .005346221 70
    2019 "Belarus"                                 114 .031008083 69
    2019 "Ecuador"                                 128  .02459262 68
    2019 "Nicaragua"                               129 .063085414 67
    2019 "Uganda"                                  151 .016038664 66
    2019 "Central African Rep."                    161 .010692443 65
    2019 "Yemen"                                   163 .016038664 64
    2019 "Azerbaijan"                              206  .04276977 63
    2019 "Angola"                                  279 .005346221 62
    2019 "Kyrgyzstan"                              294  .14434798 61
    2019 "Montenegro"                              351 .005346221 60
    2019 "Nepal"                                   382  .12189385 59
    2019 "Kenya"                                   388  .04063128 58
    2019 "Philippines"                             440  .20208716 57
    2019 "Honduras"                                500    .380651 56
    2019 "Brazil"                                  572  .27158803 55
    2019 "Rep. of Moldova"                         688  .08981652 54
    2019 "Armenia"                                 775   .1742868 53
    2019 "Cuba"                                    779   .2052949 52
    2019 "Mauritania"                              858 .032077327 51
    2019 "Lebanon"                                 948  .06736239 50
    2019 "North Macedonia"                         962  .05666995 49
    2019 "Benin"                                  1079  .12510158 48
    2019 "Chad"                                   1125  .06201617 47
    2019 "Russian Federation"                     1378  .29618067 46
    2019 "Peru"                                   1538  1.3932253 45
    2019 "Dem. Rep. of the Congo"                 1554  .12937856 44
    2019 "Algeria"                                1815  .19460246 43
    2019 "Libya"                                  2006   .4170053 42
    2019 "Colombia"                               2019   .7302938 41
    2019 "China"                                  2147   .8030024 40
    2019 "Venezuela (Bolivarian Republic of)"     2190  1.6690903 39
    2019 "Palestinian"                            2338  .05880843 38
    2019 "Niger"                                  2380  .27479577 37
    2019 "Bosnia and Herzegovina"                 2455  .07591634 36
    2019 "Georgia"                                2770  1.4605876 35
    2019 "India"                                  3362  1.2809546 34
    2019 "Guinea-Bissau"                          3505   .6137462 33
    2019 "Iran (Islamic Rep. of)"                 3770  .28441897 32
    2019 "Albania"                                3830  1.6915444 31
    2019 "Sierra Leone"                           3892  .55173004 30
    2019 "Ethiopia"                               4386   .0844703 29
    2019 "Sri Lanka"                              4739   .6543775 28
    2019 "Liberia"                                5073  .25234166 27
    2019 "Burkina Faso"                           5200   .4832984 26
    2019 "El Salvador"                            5324   3.461144 25
    2019 "Togo"                                   5332   .4148668 24
    2019 "Syrian Arab Rep."                       5495   .1646636 23
    2019 "Egypt"                                  5584   .9772893 22
    2019 "Cameroon"                               5901   1.147299 21
    2019 "Sudan"                                  6312  .25448012 20
    2019 "Morocco"                                8410   2.731919 19
    2019 "Tunisia"                                8954    .936658 18
    2019 "Serbia and Kosovo: S/RES/1244 (1999)"  12537    .091955 17
    2019 "Ukraine"                               14079   4.284462 16
    2019 "Eritrea"                               18698  .25234166 15
    2019 "Turkey"                                18778    .647962 14
    2019 "Guinea"                                19014  3.2686796 13
    2019 "Somalia"                               21477   .7623712 12
    2019 "Afghanistan"                           24223  1.0767289 11
    2019 "Ghana"                                 27416  3.0537615 10
    2019 "Iraq"                                  27787    1.16013  9
    2019 "Unknown "                              29675   .6319234  8
    2019 "Cote d'Ivoire"                         30043  4.0075274  7
    2019 "Senegal"                               34656   6.072238  6
    2019 "Mali"                                  41200  4.4929643  5
    2019 "Gambia"                                41284   4.701467  4
    2019 "Bangladesh"                            44483   8.867243  3
    2019 "Pakistan"                              67565   12.84804  2
    2019 "Nigeria"                              117634  17.823233  1
    end
    I would like to create a bar graph that show contemporaneusly: tot_demand_c rec_over_tot if newgra. I wrote the following code
    [/CODE]
    graph bar tot_demand_c rec_over_tot if newgra <=50 , over ( Countryoforigin ,sort(1)label(nolabel))blabel(group, position (outside) orientation(vertical) size(vsmall)) graphregion(color(white)) ytitle(Total demand, size (small))
    [/CODE]
    However I wonder if there was a way to display the name for each bar only once and not above both variables.
    Can you please help me?
    Thank you for your attention

  • #2
    Maybe this looks better?

    Code:
    graph bar tot_demand_c rec_over_tot if newgra <=50 , over (Countryoforigin, sort(1) label(nolabel)) blabel(group, position(outside) orientation(vertical) size(vsmall)) graphregion(color(white)) ytitle(Total demand, size(small)) stack
    I think the overall layout could be further improved. For example, bars and country names could be horizontal.The rec_over_tot is much smaller than tot_demand_c, and displaying the two variables at the same scale may not be informative.

    Comment


    • #3
      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input int Year str36 Countryoforigin float(tot_rec tot_reje tot_demand_c newgra)
      2019 "Afghanistan"                          3468  3705  24223 11
      2019 "Albania"                               365  2797   3830 31
      2019 "Algeria"                                86  1501   1815 43
      2019 "Angola"                                 92   118    279 62
      2019 "Argentina"                               0    18     23 83
      2019 "Armenia"                               140   329    775 53
      2019 "Azerbaijan"                             92    69    206 63
      2019 "Bangladesh"                            878 33541  44483  3
      2019 "Belarus"                                 0    74    114 69
      2019 "Benin"                                  58   726   1079 48
      2019 "Bolivia (Plurinational State of)"        5    43     63 75
      2019 "Bosnia and Herzegovina"                 53  1703   2455 36
      2019 "Brazil"                                105   344    572 55
      2019 "Burkina Faso"                          145  3698   5200 26
      2019 "Burundi"                                15     0     40 77
      2019 "Cabo Verde"                             17     5     22 84
      2019 "Cameroon"                             1191  2898   5901 21
      2019 "Central African Rep."                   58    25    161 65
      2019 "Chad"                                  120   569   1125 47
      2019 "Chile"                                   0    20     20 85
      2019 "China"                                 171  1818   2147 40
      2019 "Colombia"                              488   949   2019 41
      2019 "Cote d'Ivoire"                        1534 18221  30043  7
      2019 "Cuba"                                   93   454    779 52
      2019 "Dem. Rep. of the Congo"                635   459   1554 44
      2019 "Dominican Rep."                          5    72     92 71
      2019 "Ecuador"                                 5    88    128 68
      2019 "Egypt"                                 523  3044   5584 22
      2019 "El Salvador"                          1208  1970   5324 25
      2019 "Eritrea"                              5064  2675  18698 15
      2019 "Ethiopia"                             1402   979   4386 29
      2019 "Gabon"                                   0    60     85 72
      2019 "Gambia"                               1250 27551  41284  4
      2019 "Georgia"                               245  1946   2770 35
      2019 "Ghana"                                 450 20654  27416 10
      2019 "Guatemala"                               5    15     25 81
      2019 "Guinea"                                705 12495  19014 13
      2019 "Guinea-Bissau"                          25  2550   3505 33
      2019 "Honduras"                              131   211    500 56
      2019 "India"                                 128  2774   3362 34
      2019 "Iran (Islamic Rep. of)"               1827  1061   3770 32
      2019 "Iraq"                                 2723 19033  27787  9
      2019 "Jordan"                                 20    43     68 74
      2019 "Kazakhstan"                             15    31     61 76
      2019 "Kenya"                                  60   221    388 58
      2019 "Kyrgyzstan"                             28   195    294 61
      2019 "Lebanon"                               221   399    948 50
      2019 "Liberia"                               105  3624   5073 27
      2019 "Libya"                                 398   510   2006 42
      2019 "Liechtenstein"                           0     5      5 91
      2019 "Madagascar"                              0    15     35 80
      2019 "Mali"                                  568 24450  41200  5
      2019 "Mauritania"                            175   435    858 51
      2019 "Mauritius"                               0    26     36 79
      2019 "Mexico"                                  5    10     15 87
      2019 "Montenegro"                              0   270    351 60
      2019 "Morocco"                               375  6458   8410 19
      2019 "Nepal"                                  24   257    382 59
      2019 "Nicaragua"                              28    76    129 67
      2019 "Niger"                                  80  1626   2380 37
      2019 "Nigeria"                              6027 88389 117634  1
      2019 "North Macedonia"                        25   815    962 49
      2019 "Pakistan"                             3442 45190  67565  2
      2019 "Palestinian"                           916  1093   2338 38
      2019 "Paraguay"                                0     5     10 89
      2019 "Peru"                                  140  1286   1538 45
      2019 "Philippines"                            15   314    440 57
      2019 "Rep. of Moldova"                        26   514    688 54
      2019 "Russian Federation"                    364   739   1378 46
      2019 "Rwanda"                                 46    32     83 73
      2019 "Senegal"                               762 25837  34656  6
      2019 "Serbia and Kosovo: S/RES/1244 (1999)" 1050  9065  12537 17
      2019 "Sierra Leone"                          270  2655   3892 30
      2019 "Somalia"                              4368  2046  21477 12
      2019 "South Africa"                            0     5     15 87
      2019 "South Sudan"                            10     5     20 85
      2019 "Sri Lanka"                             580  3287   4739 28
      2019 "Sudan"                                1372  2536   6312 20
      2019 "Syrian Arab Rep."                     3602  1213   5495 23
      2019 "Tajikistan"                              5     5     10 89
      2019 "Togo"                                  583  2927   5332 24
      2019 "Tunisia"                               139  8059   8954 18
      2019 "Turkey"                               2050 14287  18778 14
      2019 "Uganda"                                 63    63    151 66
      2019 "Ukraine"                               362  7553  14079 16
      2019 "United Rep. of Tanzania"                10    25     40 77
      2019 "United States of America"                0     5      5 91
      2019 "Unknown "                             1166 16736  29675  8
      2019 "Venezuela (Bolivarian Republic of)"    607   201   2190 39
      2019 "Viet Nam"                                5    10     25 81
      2019 "Yemen"                                  77    15    163 64
      2019 "Zimbabwe"                               15    63     98 70
      end
      Hi Fei Wang thanks for your help, you right, infact I taken the wrong variable. Here the correct ones but when I try your code with new variables the name of countries appear unclear. Have you any suggestion please?

      Thank you for your help.

      Code:
      graph bar tot_demand_c tot_rec tot_reje if newgra <=50 , over (Countryoforigin, sort(1) label(nolabel)) blabel(group, position(outside) orientation(vertical) size(vsmall)) graphregion(color(white)) ytitle(Total demand, size(small)) stack

      Comment


      • #4
        How about this:

        Code:
        graph hbar tot_demand_c tot_rec tot_reje if newgra <=50 , over(Countryoforigin, sort(1) label(angle(horizontal) labs(tiny))) graphregion(color(white)) ytitle(Total demand, size(small)) ylab(,labs(small)) stack leg(off)

        Comment


        • #5
          That's perfect! Thank you a lot.

          Comment

          Working...
          X