Announcement

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

  • Decluttering hbar graph

    Hello and apologies for cross posing. I am looking to produce a hbar graph that displays the totals for each bar, however currently the graph is very cluttered. I would also like to enlarge the size of the bars. Below is an example of the data and my current code which produces the following graph. Any suggestions or advice would be greatly appreciated. Thank you!

    Adam

    Code:
    graph hbar (sum) year1_energy_GWh, over(scenario_2) over(state_abbr_1, gap(*3)) asyvars legend(position(6)  rows(1)) blabel(total) ytitle("First Year FPV Generation (GWh)") title("FPV Estimates by Scenario in the Northeast")
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str2 state_abbr_1 str25 scenario_2 float year1_energy_GWh
    "CT" "Open"                      1.2581414
    "CT" "Biodiversity Conservation"  1.240995
    "CT" "Open"                       1.234315
    "CT" "Resilience"                2.3201365
    "CT" "Biodiversity Conservation" 1.2387027
    "CT" "Biodiversity Conservation" 1.2459012
    "CT" "Resilience"                 1.253525
    "CT" "Resilience"                11.332708
    "CT" "Resilience"                 1.235578
    "CT" "Biodiversity Conservation"  1.229009
    "CT" "Open"                       1.237945
    "CT" "Resilience"                1.2375426
    "CT" "Open"                      1.4528956
    "CT" "Biodiversity Conservation"  1.260093
    "CT" "Resilience"                1.2383895
    "CT" "Biodiversity Conservation" 1.2306623
    "CT" "Biodiversity Conservation" 1.2306623
    "CT" "Biodiversity Conservation" 1.2512425
    "CT" "Biodiversity Conservation"  1.207899
    "CT" "Precautionary/Co-Benefits"  4.556657
    "CT" "Precautionary/Co-Benefits"  3.666552
    "CT" "Biodiversity Conservation" 1.2791827
    "CT" "Open"                        1.20909
    "CT" "Precautionary/Co-Benefits"  31.46854
    "CT" "Biodiversity Conservation" 16.580193
    "CT" "Biodiversity Conservation" 1.6694952
    "CT" "Open"                      1.2456912
    "CT" "Open"                      1.2500556
    "CT" "Biodiversity Conservation"  1.266009
    "CT" "Open"                       1.261932
    "CT" "Precautionary/Co-Benefits" 64.658875
    "CT" "Precautionary/Co-Benefits"  9.433941
    "CT" "Precautionary/Co-Benefits"  54.69945
    "CT" "Resilience"                 8.145659
    "CT" "Resilience"                 5.500001
    "CT" "Precautionary/Co-Benefits" 1.2863942
    "CT" "Biodiversity Conservation"  41.93174
    "CT" "Open"                       5.133237
    "CT" "Biodiversity Conservation"  1.257524
    "CT" "Biodiversity Conservation" 1.2617728
    "CT" "Biodiversity Conservation"  1.260093
    "CT" "Open"                      1.2266812
    "CT" "Open"                      1.2261162
    "CT" "Precautionary/Co-Benefits"  6.246189
    "CT" "Open"                      1.2129014
    "CT" "Open"                      1.2263212
    "CT" "Biodiversity Conservation"  1.266009
    "CT" "Open"                       5.750137
    "CT" "Precautionary/Co-Benefits" 1.5864046
    "CT" "Resilience"                1.2485183
    "CT" "Open"                      1.2446864
    "CT" "Open"                      1.2594215
    "CT" "Precautionary/Co-Benefits"  2.466801
    "CT" "Biodiversity Conservation"   1.24085
    "CT" "Biodiversity Conservation" 3.9789596
    "CT" "Precautionary/Co-Benefits"  3.081274
    "CT" "Resilience"                1.2577695
    "CT" "Open"                      3.6380885
    "CT" "Biodiversity Conservation" 1.2695323
    "CT" "Biodiversity Conservation" 1.2384125
    "CT" "Open"                      1.2284822
    "CT" "Biodiversity Conservation"     1.242
    "CT" "Biodiversity Conservation"  54.82994
    "CT" "Open"                       9.574749
    "CT" "Open"                      1.2551342
    "CT" "Open"                      1.2465488
    "CT" "Biodiversity Conservation"  4.323983
    "CT" "Biodiversity Conservation"  1.229009
    "CT" "Open"                      1.7733105
    "CT" "Resilience"                1.2450868
    "CT" "Resilience"                1.2532253
    "CT" "Biodiversity Conservation" 1.2573873
    "CT" "Biodiversity Conservation"  4.252918
    "CT" "Precautionary/Co-Benefits"  9.346328
    "CT" "Biodiversity Conservation" 1.2554654
    "CT" "Biodiversity Conservation"  1.249973
    "CT" "Biodiversity Conservation"   1.20978
    "CT" "Biodiversity Conservation" 1.2358438
    "CT" "Precautionary/Co-Benefits" 2.9427836
    "CT" "Biodiversity Conservation"  5.171657
    "CT" "Resilience"                1.6790197
    "CT" "Resilience"                2.3656929
    "CT" "Open"                       1.214149
    "CT" "Resilience"                 1.255452
    "CT" "Biodiversity Conservation" 2.2831388
    "CT" "Biodiversity Conservation" 12.151608
    "CT" "Biodiversity Conservation" 1.6474732
    "CT" "Resilience"                1.2368176
    "CT" "Resilience"                 1.218013
    "CT" "Precautionary/Co-Benefits" 15.585084
    "CT" "Precautionary/Co-Benefits" 1.2568663
    "CT" "Biodiversity Conservation" 1.2671353
    "CT" "Precautionary/Co-Benefits"  1.975887
    "CT" "Open"                       1.236581
    "CT" "Biodiversity Conservation"  1.267726
    "CT" "Open"                      1.6308695
    "CT" "Open"                      1.2263212
    "CT" "Open"                       13.56239
    "CT" "Biodiversity Conservation" 1.2554654
    "CT" "Resilience"                 2.854018
    end

    Graph.gph

  • #2
    If you decide to show bar labels, then lose the axis. But with many bars, you might just as well keep the axis and lose the labels. Also, no need for a horizontal bar graph as your categorical axis labels are two-letter state abbreviations, and these do not occupy much space. I lose your value labels after extracting data from your GPH file. Here, the dataex example doesn't reproduce issues present in final graph. For your future posts, note the FAQ recommendation to post images in .PNG format (FAQ Advice #12).

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input double year1_energy_GWh long(scenario_2 state_abbr_1)
     645.3456429243088 4 14
    116.01218342781067 3 14
     507.0778844356537 2 14
     49.29666221141815 1 14
    1740.1988728046417 4 13
     222.2658587694168 3 13
    476.45402014255524 2 13
     635.3092620372772 1 13
    3953.2825136184692 4 12
     878.6953831911087 3 12
     3824.150146961212 2 12
     985.5638434886932 1 12
     6.787279009819031 4 11
    128.22882914543152 3 11
     331.2821681499481 2 11
    155.66115486621857 1 11
    1446.4568309783936 4 10
    1085.4542719125748 3 10
    2311.0088073015213 2 10
     966.9815781116486 1 10
    4843.9170969724655 4  9
    2132.6208270788193 3  9
     7645.848917126656 2  9
    3793.3879936933517 1  9
     629.8197330236435 4  8
     414.6602112054825 3  8
    1304.2275236845016 2  8
    1455.6401339769363 1  8
    1060.1795673370361 4  7
    217.53243947029114 3  7
     724.1327208280563 2  7
    1320.6840151548386 1  7
    3148.2715690135956 4  6
     281.9400637149811 3  6
     752.2063937187195 2  6
    1416.2461141347885 1  6
     560.6265503168106 4  5
      302.724196434021 3  5
    289.34070348739624 2  5
     402.3209071159363 1  5
     591.9392572641373 4  4
     785.7292594909668 3  4
    1698.2314969301224 2  4
     4471.110173821449 1  4
     205.9047886133194 4  3
       68.716827750206 3  3
    122.32708466053009 2  3
     257.3176989555359 1  3
                     . 4  2
                     . 3  2
                     . 2  2
    10.392961263656616 1  2
    220.08254253864288 4  1
     512.0057880878448 3  1
     705.4831033945084 2  1
      895.430302977562 1  1
    end
    
    graph bar (sum) year1_energy_GWh, over(scenario_2) ///
    over(state_abbr_1, gap(*1) sort(1)) asyvars ytitle("First Year FPV Generation (GWh)") ///
    title("FPV Estimates by Scenario in the Northeast") blab(total, size(vsmall) orientation(vert) ///
    format("%4.0f")) ylab("") leg(pos(10) col(1)  ring(0)) graphregion(margin(zero))
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	50.0 KB
ID:	1734640

    Last edited by Andrew Musau; 21 Nov 2023, 15:36.

    Comment


    • #3
      Thank you, Andrew for the suggestions for this graph. Your advice was helpful, I will look into FAQ #12 as will for future posts that include figures.

      Comment


      • #4
        Inspired by Andrew Musau's very helpful answer, I decided to play with tabplot from the Stata Journal, with an assist from myaxis from the Stata Journal.

        Code:
        clear
        input double year1_energy_GWh long(scenario_2 state_abbr_1)
         645.3456429243088 4 14
        116.01218342781067 3 14
         507.0778844356537 2 14
         49.29666221141815 1 14
        1740.1988728046417 4 13
         222.2658587694168 3 13
        476.45402014255524 2 13
         635.3092620372772 1 13
        3953.2825136184692 4 12
         878.6953831911087 3 12
         3824.150146961212 2 12
         985.5638434886932 1 12
         6.787279009819031 4 11
        128.22882914543152 3 11
         331.2821681499481 2 11
        155.66115486621857 1 11
        1446.4568309783936 4 10
        1085.4542719125748 3 10
        2311.0088073015213 2 10
         966.9815781116486 1 10
        4843.9170969724655 4  9
        2132.6208270788193 3  9
         7645.848917126656 2  9
        3793.3879936933517 1  9
         629.8197330236435 4  8
         414.6602112054825 3  8
        1304.2275236845016 2  8
        1455.6401339769363 1  8
        1060.1795673370361 4  7
        217.53243947029114 3  7
         724.1327208280563 2  7
        1320.6840151548386 1  7
        3148.2715690135956 4  6
         281.9400637149811 3  6
         752.2063937187195 2  6
        1416.2461141347885 1  6
         560.6265503168106 4  5
          302.724196434021 3  5
        289.34070348739624 2  5
         402.3209071159363 1  5
         591.9392572641373 4  4
         785.7292594909668 3  4
        1698.2314969301224 2  4
         4471.110173821449 1  4
         205.9047886133194 4  3
           68.716827750206 3  3
        122.32708466053009 2  3
         257.3176989555359 1  3
                         . 4  2
                         . 3  2
                         . 2  2
        10.392961263656616 1  2
        220.08254253864288 4  1
         512.0057880878448 3  1
         705.4831033945084 2  1
          895.430302977562 1  1
        end
        
        graph bar (sum) year1_energy_GWh, over(scenario_2) ///
        over(state_abbr_1, gap(*1) sort(1)) asyvars ytitle("First Year FPV Generation (GWh)") ///
        title("FPV Estimates by Scenario in the Northeast") blab(total, size(vsmall) orientation(vert) ///
        format("%4.0f")) ylab("") leg(pos(10) col(1)  ring(0)) graphregion(margin(zero))
        
        collapse (sum) year1_energy_GWh, by(scenario_2 state_abbr_1)
        
        myaxis xshow=state_abbr_1, sort(total year1_energy_GWh) descending
        
        tabplot scenario_2 xshow [iw=year1_energy_GWh], subtitle("First Year FPV Generation (GWh)") ///
        title("FPV Estimates by Scenario in the Northeast") showval(format("%4.0f")) separate(scenario_2) ///
        ytitle(better text about scenarios) xtitle(better text about states)
        Click image for larger version

Name:	anothertabplot.png
Views:	1
Size:	72.6 KB
ID:	1735280

        Comment


        • #5
          If these are states of the North-Eastern USA, then there is room for two-letter abbreviations such as MA, ME and RI on both Andrew's graph and mine.

          Comment


          • #6
            Hello Nick, thank you for providing an alterative to the box plot provided by Andrew. Having choices helps broaden the door to how the data is ultimately presented.

            Comment

            Working...
            X