Announcement

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

  • Combining stacked plots in one diagram

    I'm trying to create a diagram like the one shown below. The different variables each stand for one attribute ranked by interviewees from 1 (unimportant) to 5 (very important).

    Here an example of my dataset:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte(taste price sustainable animal_health regional organic)
    5 5 5 5 5 4
    4 3 4 4 4 4
    4 4 4 3 4 4
    4 4 5 4 4 4
    3 1 5 5 5 5
    5 5 5 4 5 4
    5 4 4 5 5 4
    4 3 5 5 5 5
    5 4 4 4 4 4
    5 3 4 3 2 2
    5 4 4 4 4 5
    5 5 4 4 3 4
    5 4 4 5 4 4
    5 5 4 4 4 4
    4 4 3 4 3 3
    4 4 3 2 3 2
    5 5 4 3 5 4
    4 5 5 2 5 4
    4 4 4 4 4 3
    4 4 3 2 3 3
    end
    This is the diagram I want to create:
    Click image for larger version

Name:	plot.png
Views:	1
Size:	31.5 KB
ID:	1684702


    I've been trying it with -catplot- and -graph hbar-, but I fail to get the desired result.
    I'd be very thankful for your help!


  • #2
    catplot is from SSC.

    You need a different data structure to make good progress.

    Here I use tabplot from the Stata Journal; see also floatplot from SSC and indeed catplot.

    Many posts here advance arguments against stacked bar charts, a popular but flawed design. See for example https://www.statalist.org/forums/for...updated-on-ssc

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte(taste price sustainable animal_health regional organic)
    5 5 5 5 5 4
    4 3 4 4 4 4
    4 4 4 3 4 4
    4 4 5 4 4 4
    3 1 5 5 5 5
    5 5 5 4 5 4
    5 4 4 5 5 4
    4 3 5 5 5 5
    5 4 4 4 4 4
    5 3 4 3 2 2
    5 4 4 4 4 5
    5 5 4 4 3 4
    5 4 4 5 4 4
    5 5 4 4 4 4
    4 4 3 4 3 3
    4 4 3 2 3 2
    5 5 4 3 5 4
    4 5 5 2 5 4
    4 4 4 4 4 3
    4 4 3 2 3 3
    end
    
    gen long id = _n
    rename (taste-organic) (y=)
    reshape long y, i(id) j(which) string
    
    replace which = "animal health" if which == "animal_health"
    set scheme s1color
    tabplot which y, horizontal percent(which) showval(format(%2.0f)) ytitle("more good words here") xtitle("good words here") subtitle(%) separate(y) bar1(color(red)) bar2(fcolor(red*0.4) lcolor(red)) bar3(fcolor(blue*0.2) lcolor(blue)) bar4(fcolor(blue*0.6) lcolor(blue)) bar5(color(blue))
    Click image for larger version

Name:	yatabplot.png
Views:	1
Size:	29.1 KB
ID:	1684710

    Last edited by Nick Cox; 07 Oct 2022, 03:47.

    Comment


    • #3
      Hi Nick, thank you very much, it worked!
      Last edited by Nora Fingado; 07 Oct 2022, 07:43.

      Comment


      • #4
        Here is some code for floatplot:

        Code:
        floatplot y, over(which) ytitle("more good words here") xtitle("good words here")  fcolors(red red*0.4  blue*0.2 blue*0.6 blue) lcolors(red red blue blue blue) centre(3)

        Comment


        • #5
          In fact, what I presume are @Nora Fingado's full results can be read off the graph in #1. With the usual kinds of reservations about (e.g.) axis titles and colour choice (perhaps shades of green match the substance here), here are token tabplot and floatplot results for the data in #1.

          I'd recommend sorting questions according to the mean result. Despite reams of advice about not taking means over Likert items, sorting on the mean does help. Much more on sorting to get better axes at https://journals.sagepub.com/doi/pdf...6867X211045582 which documents the myaxis command.

          Both graphs can be presented with transposed axes.

          Code:
          clear
          input str13 which byte grade float(percent mean)
          "animal health" 1  6 3.69
          "animal health" 2  7 3.69
          "animal health" 3 27 3.69
          "animal health" 4 32 3.69
          "animal health" 5 28 3.69
          "ecological"    1  9 3.32
          "ecological"    2 11 3.32
          "ecological"    3 35 3.32
          "ecological"    4 29 3.32
          "ecological"    5 16 3.32
          "price"         1  2 3.97
          "price"         2  4 3.97
          "price"         3 26 3.97
          "price"         4 31 3.97
          "price"         5 37 3.97
          "regional"      1  6 3.62
          "regional"      2  9 3.62
          "regional"      3 26 3.62
          "regional"      4 35 3.62
          "regional"      5 24 3.62
          "sustainable"   1  7 3.57
          "sustainable"   2  8 3.57
          "sustainable"   3 29 3.57
          "sustainable"   4 33 3.57
          "sustainable"   5 23 3.57
          "taste"         1  1 4.57
          "taste"         2  1 4.57
          "taste"         3  5 4.57
          "taste"         4 26 4.57
          "taste"         5 67 4.57
          end
          
          myaxis order=which, sort(mean mean)
          
          tabplot order grade [fw=percent] , ///
          horizontal showval(format(%2.0f) offset(0.17)) ytitle("question") xtitle("answer") subtitle(%) separate(grade) bar1(color(red)) bar2(fcolor(red*0.4) lcolor(red)) bar3(fcolor(blue*0.2) lcolor(blue)) bar4(fcolor(blue*0.6) lcolor(blue)) bar5(color(blue)) name(NF1, replace)
          
          
          floatplot grade [w=percent], over(order) xtitle("answer") ytitle("question")  fcolors(red red*0.4  blue*0.2 blue*0.6 blue) lcolors(red red blue blue blue) centre(3) name(NF2, replace)
          Click image for larger version

Name:	NF1.png
Views:	1
Size:	28.5 KB
ID:	1684875

          Click image for larger version

Name:	NF2.png
Views:	1
Size:	26.3 KB
ID:	1684876

          Last edited by Nick Cox; 09 Oct 2022, 06:04.

          Comment


          • #6
            Hello, I am looking to do something similar. I would like to take my stacked bar graph and convert it into a tabplot showing the percent of each water type by state. The main issue I am running into is when I go to label the bars, given that some categories of water type are so small, the labels bunch up. Any advice would be helpful. Below is the code for my stacked bar graph.

            Thank you.

            Code:
            graph hbar (sum) year1_energy_GWh if Social_Conservation ==1, percentages over(Water_Type) over(state_abbr_1) asyvars bar(1, color("0 107 162")) bar(2, color("123 191 252")) bar(3, color("235 180 52")) bar(4, color("219 68 75")) bar(5, color("55 154 139")) bar(6, color("117 141 153")) bar(7, color("0 120 107")) bar(8, color("230 78 83")) bar(9, color("201 140 172")) bar(10, color("191 216 229"))  legend(cols(3) rows(3)) ytitle("Percent Sum of Annual FPV Generation (GWH)")stack

            Code:
            * Example generated by -dataex-. For more info, type help dataex
            clear
            input float year1_energy_GWh str22 Water_Type str2 state_abbr_1 float(Climate_Crisis Conservation Social Social_Conservation)
              1.93216 "Recreation"             "NY" 1 1 0 0
             169.7592 "Risk Reduction"         "NY" 1 0 0 0
             2.108194 "Lake or Pond"           "ME" 1 0 1 0
             43.44899 "Lake or Pond"           "VT" 1 0 1 0
              38.9889 "Lake or Pond"           "NY" 1 0 1 0
            37.129242 "Lake or Pond"           "NY" 1 0 1 0
             624.3201 "Lake or Pond"           "NY" 1 1 1 1
            218.34544 "Lake or Pond"           "NY" 1 0 1 0
            228.22026 "Lake or Pond"           "VT" 1 0 1 0
            111.85027 "Lake or Pond"           "NY" 1 1 1 1
            16.428026 "Risk Reduction"         "PA" 1 0 0 0
             70.78135 "Lake or Pond"           "NY" 1 0 1 0
             105.1185 "Risk Reduction"         "NY" 1 1 0 0
             8.229448 "Lake or Pond"           "NY" 1 0 1 0
             1.146294 "Lake or Pond"           "NY" 1 0 1 0
            35.327465 "Lake or Pond"           "VT" 1 0 1 0
             24.80427 "Lake or Pond"           "VT" 1 0 1 0
            120.13203 "Lake or Pond"           "NY" 1 0 1 0
            113.66757 "Risk Reduction"         "NY" 1 1 0 0
             5.177037 "Recreation"             "VT" 1 0 0 0
             30.91308 "Lake or Pond"           "NY" 1 1 1 1
              41.8978 "Risk Reduction"         "VA" 1 0 0 0
            1.3351754 "Risk Reduction"         "VA" 1 0 0 0
            1.4549874 "Lake or Pond"           "NY" 1 0 1 0
             5.621578 "Risk Reduction"         "NY" 1 1 0 0
             190.8287 "Lake or Pond"           "NY" 1 1 1 1
            24.177967 "Lake or Pond"           "NY" 1 1 1 1
             6.201077 "Lake or Pond"           "VT" 1 0 1 0
             6.338756 "Lake or Pond"           "NY" 1 0 1 0
             3.574237 "Lake or Pond"           "ME" 1 1 1 1
             105.0657 "Lake or Pond"           "VT" 1 0 1 0
            301.85693 "Lake or Pond"           "VT" 1 0 1 0
               8.7601 "Lake or Pond"           "NY" 1 0 1 0
             123.8275 "Risk Reduction"         "NY" 1 1 0 0
            3.7057636 "Lake or Pond"           "NY" 1 1 1 1
            2.0399938 "Lake or Pond"           "NY" 1 0 1 0
             5.649439 "Lake or Pond"           "VT" 1 0 1 0
              5.63961 "Water Supply"           "NY" 1 1 1 1
             476.5151 "Lake or Pond"           "NY" 1 0 1 0
             55.57685 "Lake or Pond"           "VT" 1 0 1 0
            1.1443901 "Lake or Pond"           "NY" 1 1 1 1
             46.58501 "Lake or Pond"           "VT" 1 0 1 0
            14.701073 "Lake or Pond"           "VT" 1 0 1 0
             50.91717 "Lake or Pond"           "NY" 1 1 1 1
             214.2728 "Lake or Pond"           "VT" 1 0 1 0
            119.61813 "Risk Reduction"         "PA" 1 0 0 0
             6.163414 "Lake or Pond"           "VT" 1 1 1 1
            4.2258396 "Lake or Pond"           "NY" 1 0 1 0
             50.49245 "Lake or Pond"           "VT" 1 0 1 0
            3.7004704 "Lake or Pond"           "NY" 1 0 1 0
             47.53394 "Recreation"             "NY" 1 0 0 0
             3.640743 "Lake or Pond"           "PA" 1 1 1 1
            100.15274 "Water Supply"           "MD" 1 1 0 0
             6.680492 "Recreation"             "NY" 1 0 0 0
             120.2446 "Hydroelectric"          "VA" 1 0 1 0
              47.5085 "Lake or Pond"           "NY" 1 0 1 0
             41.54034 "Lake or Pond"           "VT" 1 0 1 0
            1.1461967 "Hydroelectric"          "NY" 1 0 1 0
            10.346958 "Lake or Pond"           "NY" 1 0 1 0
            21.072365 "Other"                  "PA" 1 1 0 0
             1.827428 "Risk Reduction"         "VA" 1 1 0 0
              2.67879 "Water Supply"           "PA" 1 1 1 1
            25.142197 "Lake or Pond"           "ME" 1 1 1 1
             7.440428 "Lake or Pond"           "ME" 1 0 1 0
              59.9289 "Lake or Pond"           "ME" 1 0 1 0
            1.1941066 "Other"                  "WV" 1 1 1 1
             5.917602 "Water Supply"           "MA" 1 1 1 1
            10.798596 "Recreation"             "NY" 1 0 0 0
            13.159533 "Hydroelectric"          "VT" 1 0 1 0
            4.6757894 "Lake or Pond"           "VT" 1 0 1 0
             67.00056 "Lake or Pond"           "NY" 1 1 1 1
             3.759181 "Water Supply"           "PA" 1 0 1 0
            19.398064 "Recreation"             "VT" 1 0 0 0
            18.868528 "Hydroelectric"          "NJ" 1 0 1 0
             3.371299 "Recreation"             "VT" 1 1 0 0
             55.26851 "Risk Reduction"         "PA" 1 0 1 0
             46.96778 "Hydroelectric"          "NY" 1 0 1 0
             5.633872 "Recreation"             "NY" 1 0 0 0
             2.740364 "Lake or Pond"           "PA" 1 0 1 0
            1.6525086 "Other"                  "PA" 1 1 0 0
             48.76981 "Hydroelectric"          "ME" 1 0 1 0
            1.3350573 "Water Supply"           "MD" 1 1 0 0
            11.101223 "Lake or Pond"           "ME" 1 0 1 0
            1.1501387 "Water Supply"           "PA" 1 1 1 1
            22.526344 "Water Supply"           "PA" 1 0 1 0
            15.826205 "Recreation"             "NY" 1 0 0 0
            190.44966 "Lake or Pond"           "NY" 1 0 1 0
            12.303912 "Water Supply"           "PA" 1 1 1 1
              44.2809 "Lake or Pond"           "NY" 1 0 1 0
             75.01971 "Recreation"             "NY" 1 0 0 0
             9.803587 "Other"                  "WV" 1 1 1 1
             45.24949 "Hydroelectric"          "NY" 1 0 1 0
             156.0941 "Lake or Pond"           "NY" 1 0 1 0
             19.94943 "Water Supply"           "PA" 1 1 1 1
            1.3081514 "Hydroelectric"          "VA" 1 0 1 0
            13.468673 "Lake or Pond"           "NY" 1 1 1 1
            1.2485906 "Water Supply"           "PA" 1 1 1 1
             99.22542 "Hydroelectric"          "VT" 1 0 1 0
            1.1596742 "Lake or Pond"           "VT" 1 0 1 0
            111.78707 "Hydroelectric"          "PA" 1 0 1 0
            2.1570952 "Lake or Pond"           "ME" 1 0 1 0
             10.28173 "Hydroelectric"          "VA" 1 0 1 0
             3.578048 "Lake or Pond"           "NY" 1 1 1 1
             1.592427 "Water Supply"           "VT" 1 1 1 1
             52.24898 "Hydroelectric"          "ME" 1 0 0 0
             1.689612 "Hydroelectric"          "VA" 1 0 1 0
            10.295638 "Recreation"             "PA" 1 1 0 0
            3.3398435 "Water Supply"           "NY" 1 0 1 0
             7.884843 "Hydroelectric"          "VA" 1 0 1 0
             37.96399 "Water Supply"           "CT" 1 0 1 0
            4.3217916 "Hydroelectric"          "VT" 1 0 1 0
            12.593694 "Lake or Pond"           "VT" 1 1 1 1
            11.095502 "Water Supply"           "PA" 1 1 1 1
            2.3295681 "Lake or Pond"           "NY" 1 0 1 0
             3.287761 "Water Supply"           "PA" 1 1 1 1
            2.3279438 "Hydroelectric"          "ME" 1 0 1 0
             27.41384 "Risk Reduction"         "ME" 1 0 0 0
            32.965603 "Lake or Pond"           "ME" 1 0 1 0
             18.92975 "Risk Reduction"         "VA" 1 0 0 0
             7.613647 "Lake or Pond"           "VT" 1 0 1 0
            16.030571 "Lake or Pond"           "NY" 1 0 1 0
            15.034162 "Lake or Pond"           "ME" 1 1 1 1
               8.7446 "Water Supply"           "MD" 1 1 0 0
             9.224081 "Water Supply"           "PA" 1 1 1 1
             1.317796 "Hydroelectric"          "VA" 1 0 1 0
              115.848 "Lake or Pond"           "NY" 1 1 1 1
             52.29498 "Lake or Pond"           "NY" 1 1 1 1
            31.098013 "Lake or Pond"           "NY" 1 0 1 0
             2.505334 "Lake or Pond"           "VT" 1 0 1 0
             44.82278 "Lake or Pond"           "MD" 1 0 1 0
             64.17218 "Recreation"             "ME" 1 1 0 0
            1.6265848 "Hydroelectric"          "VA" 1 0 1 0
            217.18843 "Risk Reduction"         "VA" 1 0 0 0
             2.999196 "Lake or Pond"           "ME" 1 0 1 0
              45.8706 "Hydroelectric"          "NY" 1 0 1 0
             39.49137 "Hydroelectric"          "VT" 1 0 0 0
              2.92785 "Hydroelectric"          "VA" 1 0 1 0
              7.82372 "Risk Reduction"         "ME" 1 1 0 0
             8.155303 "Lake or Pond"           "ME" 1 0 1 0
            2.0964572 "Lake or Pond"           "NH" 1 0 1 0
            64.227776 "Recreation"             "ME" 1 1 0 0
             1.217237 "Lake or Pond"           "MA" 1 0 1 0
            2.7952375 "Hydroelectric"          "VT" 1 0 0 0
             95.77222 "Fish and Wildlife Pond" "MA" 1 0 0 0
            1.2192464 "Lake or Pond"           "ME" 1 0 1 0
            1.6473067 "Hydroelectric"          "ME" 1 0 0 0
            1.9141165 "Lake or Pond"           "NY" 1 1 1 1
            246.95604 "Lake or Pond"           "NY" 1 1 1 1
            29.366207 "Lake or Pond"           "NY" 1 0 1 0
             6.428212 "Lake or Pond"           "ME" 1 0 1 0
             20.49688 "Recreation"             "NY" 1 1 0 0
            11.629678 "Hydroelectric"          "NY" 1 1 1 1
             14.67574 "Fish and Wildlife Pond" "MA" 1 0 0 0
            108.23373 "Hydroelectric"          "VT" 1 0 0 0
            114.65982 "Recreation"             "NH" 1 0 0 0
             9.621577 "Lake or Pond"           "ME" 1 0 1 0
            11.134255 "Lake or Pond"           "ME" 1 0 1 0
               22.277 "Recreation"             "NH" 1 0 0 0
             49.04211 "Lake or Pond"           "ME" 1 0 1 0
               39.757 "Lake or Pond"           "NH" 1 0 1 0
            37.832798 "Hydroelectric"          "ME" 1 0 1 0
            18.467005 "Lake or Pond"           "ME" 1 0 1 0
            15.215628 "Lake or Pond"           "ME" 1 0 1 0
             78.56744 "Hydroelectric"          "ME" 1 0 0 0
            1.2280238 "Water Supply"           "MA" 1 1 1 1
            19.821957 "Water Supply"           "MA" 1 0 1 0
             1.376514 "Fish and Wildlife Pond" "MA" 1 0 0 0
            16.830557 "Lake or Pond"           "ME" 1 0 1 0
             19.23455 "Recreation"             "VT" 1 1 0 0
            1.4353833 "Recreation"             "ME" 1 1 0 0
              17.9474 "Lake or Pond"           "MA" 1 0 1 0
              6.80434 "Recreation"             "NH" 1 0 0 0
             2.501301 "Lake or Pond"           "NH" 1 0 1 0
             35.31561 "Recreation"             "ME" 1 1 0 0
            2.1645687 "Lake or Pond"           "ME" 1 0 1 0
             85.09158 "Lake or Pond"           "NH" 1 0 1 0
            24.587664 "Water Supply"           "MA" 1 1 1 1
            3.9255846 "Recreation"             "NH" 1 0 0 0
            32.861813 "Hydroelectric"          "ME" 1 0 1 0
             53.90079 "Risk Reduction"         "VT" 1 1 0 0
            19.597424 "Risk Reduction"         "ME" 1 1 0 0
             23.67736 "Lake or Pond"           "NY" 1 1 1 1
             262.3842 "Fish and Wildlife Pond" "MA" 1 0 0 0
              38.3652 "Lake or Pond"           "NY" 1 0 1 0
            1.8476653 "Lake or Pond"           "NY" 1 1 1 1
            4.3581553 "Risk Reduction"         "VT" 1 1 0 0
             8.877809 "Fish and Wildlife Pond" "MA" 1 1 0 0
             8.410374 "Recreation"             "NY" 1 1 0 0
             2.634701 "Lake or Pond"           "VT" 1 1 1 1
            16.620354 "Lake or Pond"           "NH" 1 0 1 0
            4.4476924 "Lake or Pond"           "ME" 1 0 1 0
             69.25263 "Hydroelectric"          "ME" 1 0 0 0
            149.15262 "Water Supply"           "MA" 1 0 1 0
            1.1997083 "Fish and Wildlife Pond" "MA" 1 1 0 0
            30.239843 "Recreation"             "NH" 1 0 0 0
             24.67435 "Water Supply"           "MA" 1 1 1 1
            28.655195 "Hydroelectric"          "MA" 1 0 0 0
              10.2123 "Lake or Pond"           "ME" 1 0 1 0
             8.946542 "Lake or Pond"           "NY" 1 1 1 1
            168.59723 "Lake or Pond"           "NY" 1 1 1 1
            37.675823 "Recreation"             "NY" 1 0 0 0
             3.546586 "Lake or Pond"           "NY" 1 1 1 1
             23.61711 "Lake or Pond"           "NH" 1 0 1 0
             46.11922 "Hydroelectric"          "ME" 1 0 1 0
             47.18386 "Recreation"             "NH" 1 0 0 0
            134.17679 "Lake or Pond"           "NY" 1 0 1 0
            2.0331473 "Lake or Pond"           "ME" 1 1 1 1
             44.68342 "Lake or Pond"           "NH" 1 0 1 0
             3.163719 "Lake or Pond"           "NH" 1 0 1 0
            16.531433 "Hydroelectric"          "VT" 1 0 0 0
             6.412329 "Lake or Pond"           "ME" 1 1 1 1
             5.435596 "Lake or Pond"           "ME" 1 0 1 0
             3.687002 "Lake or Pond"           "NY" 1 0 1 0
            1.1127353 "Lake or Pond"           "NY" 1 0 1 0
             23.89464 "Lake or Pond"           "ME" 1 1 1 1
            13.792857 "Hydroelectric"          "MA" 1 1 1 1
            12.793903 "Lake or Pond"           "NY" 1 0 1 0
            1.2107322 "Other"                  "ME" 1 1 0 0
              53.1421 "Recreation"             "ME" 1 0 0 0
             9.985609 "Lake or Pond"           "ME" 1 1 1 1
            26.164606 "Lake or Pond"           "CT" 1 0 1 0
            14.337673 "Lake or Pond"           "ME" 1 0 1 0
            14.065588 "Hydroelectric"          "MA" 1 1 1 1
             3.351576 "Risk Reduction"         "ME" 1 1 0 0
             3.566816 "Hydroelectric"          "ME" 1 0 0 0
             1.249758 "Recreation"             "MA" 1 0 0 0
            1.1239082 "Lake or Pond"           "NY" 1 0 1 0
             146.0497 "Water Supply"           "MA" 1 0 1 0
            11.185884 "Reservoir"              "VT" 1 0 1 0
             5.878175 "Water Supply"           "NY" 1 1 1 1
             258.6473 "Lake or Pond"           "NH" 1 0 1 0
            25.146803 "Recreation"             "NH" 1 0 0 0
             4.770677 "Lake or Pond"           "NY" 1 1 1 1
             50.03479 "Hydroelectric"          "VT" 1 0 0 0
             5.663441 "Lake or Pond"           "NY" 1 0 1 0
            144.40535 "Lake or Pond"           "NY" 1 1 1 1
            16.583807 "Lake or Pond"           "NY" 1 1 1 1
             6.498003 "Lake or Pond"           "MA" 1 0 1 0
            117.09289 "Recreation"             "NY" 1 1 0 0
             15.63406 "Lake or Pond"           "ME" 1 0 1 0
            10.052534 "Lake or Pond"           "MA" 1 1 1 1
             42.32109 "Hydroelectric"          "ME" 1 0 0 0
             30.92997 "Lake or Pond"           "NH" 1 0 1 0
             21.95138 "Recreation"             "ME" 1 1 0 0
            3.8267946 "Lake or Pond"           "NY" 1 0 1 0
             8.493671 "Lake or Pond"           "NY" 1 1 1 1
            153.27625 "Lake or Pond"           "NH" 1 0 1 0
            10.401328 "Water Supply"           "MA" 1 1 1 1
             13.67569 "Lake or Pond"           "NY" 1 1 1 1
             5.431302 "Lake or Pond"           "PA" 1 1 1 1
            13.184543 "Recreation"             "PA" 1 0 0 0
             1.228474 "Risk Reduction"         "NY" 1 1 0 0
             76.41392 "Recreation"             "ME" 1 0 0 0
             165.9749 "Risk Reduction"         "NY" 1 1 1 1
            20.555523 "Other"                  "VT" 1 0 0 0
             8.573183 "Risk Reduction"         "NY" 1 1 0 0
             11.54217 "Risk Reduction"         "PA" 1 1 0 0
            13.161985 "Lake or Pond"           "MA" 1 0 1 0
             1.221318 "Lake or Pond"           "ME" 1 0 1 0
            37.566017 "Hydroelectric"          "NY" 1 1 1 1
             189.2342 "Hydroelectric"          "NY" 1 1 1 1
             14.48599 "Lake or Pond"           "ME" 1 0 1 0
            1.1550764 "Lake or Pond"           "VT" 1 1 1 1
             5.360896 "Water Supply"           "NY" 1 1 1 1
            1.1368548 "Lake or Pond"           "NY" 1 0 1 0
            1.4945035 "Lake or Pond"           "NY" 1 0 1 0
             1.406929 "Lake or Pond"           "VT" 1 1 1 1
            1.2373066 "Lake or Pond"           "NY" 1 1 1 1
             2.483941 "Recreation"             "NY" 1 1 0 0
             42.00061 "Navigation"             "NY" 1 1 0 0
            15.578338 "Navigation"             "NY" 1 1 0 0
             1.150091 "Lake or Pond"           "VT" 1 0 1 0
             5.205462 "Water Supply"           "NY" 1 1 1 1
             1.465124 "Lake or Pond"           "ME" 1 1 1 1
             54.82994 "Water Supply"           "CT" 1 0 1 0
            1.1272373 "Navigation"             "NY" 1 1 0 0
            1.1349825 "Lake or Pond"           "NY" 1 1 1 1
             4.548058 "Lake or Pond"           "NY" 1 1 1 1
             2.755966 "Hydroelectric"          "NY" 1 1 0 0
            1.2114185 "Lake or Pond"           "NY" 1 1 1 1
            1.1286052 "Recreation"             "VT" 1 0 0 0
              19.3306 "Hydroelectric"          "NY" 1 0 0 0
            1.1275243 "Lake or Pond"           "ME" 1 1 1 1
             8.327287 "Lake or Pond"           "NY" 1 0 1 0
            1.9372914 "Lake or Pond"           "NY" 1 1 1 1
             1.180382 "Water Supply"           "NY" 1 0 1 0
             6.795035 "Lake or Pond"           "ME" 1 0 1 0
            1.1675819 "Lake or Pond"           "NY" 1 0 1 0
             3.074498 "Lake or Pond"           "NY" 1 1 1 1
            1.1326357 "Lake or Pond"           "ME" 1 0 1 0
             4.303517 "Lake or Pond"           "NY" 1 0 1 0
            1.1146606 "Lake or Pond"           "NY" 1 1 1 1
            1.1892796 "Lake or Pond"           "NY" 1 0 1 0
            1.1941305 "Lake or Pond"           "NY" 1 1 1 1
             1.433028 "Lake or Pond"           "NY" 1 1 1 1
            1.1648031 "Lake or Pond"           "NY" 1 1 1 1
             1.140272 "Lake or Pond"           "NY" 1 1 1 1
              16.6505 "Lake or Pond"           "ME" 1 1 1 1
            1.1673144 "Lake or Pond"           "NY" 1 1 1 1
            1.1801285 "Lake or Pond"           "NY" 1 0 1 0
            end
            ------------------ copy up to and including the previous line ------------------

            Listed 300 out of 16146 observations

            Comment


            • #7
              What tabplot code did you try? How many states? Just some in the NE of the US or all 50? (plus DC? Puerto Rico? ???).

              Comment


              • #8
                Below is the tabplot code that I attempted to implement, although it did not turn out like my stacked bar graph. As for the states, it is all in the Northeast, CT, DE, MA, MD, ME, NH, NJ, NY, PA, RI, VA, VT, WV, and DC.
                Code:
                tabplot state_abbr_1 year1_energy_GWh, horizontal percent(Water_Type) showval(format("%3.1f")) separate(Water_Type)

                Comment


                • #9
                  tabplot wants to see a (categorical or integer) row variable and a (categorical or integer) column variable in most problems. The variable you name second

                  year1_energy_GWh

                  is not categorical or integer at all, but should be supplied as a weight. For your two other variables, alphabetical order seems dopey, and there are several ways of trying to do better. Using myaxis from the Stata Journal is one possibility. With your example data, this shows some technique.

                  Code:
                  myaxis state=state_abbr, sort(total year) descending
                  myaxis type=Water_Type, sort(total year) descending  
                  tabplot type state [iw=year], ytitle("") xtitle("") subtitle(GWh) showval(format(%1.0f)) separate(type)
                  Click image for larger version

Name:	GWh.png
Views:	1
Size:	67.1 KB
ID:	1737121

                  Comment


                  • #10
                    Thank you, I did not have a proper understanding of the tabplot data requirements. This is what I was looking for, I can adjust the data to show for each state the share of water types.

                    Comment

                    Working...
                    X