Announcement

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

  • Bar and dot plots in a two-way graph command

    Dear All,

    I am looking to create a similar graph like the one herein attached which combines both bar and dot plots into a single plot.
    Click image for larger version

Name:	Untitled.png
Views:	1
Size:	10.1 KB
ID:	1516617
    Kindly find the data that I am using:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long Category float(frequencyindex coverageratio prevalencescore regularintensity)
    1  .3943591  .4980086 2.0093305 .0003354162
    2  .3671874 .42085615 1.1860977   .01351625
    3 .26117173  .3459178  .9149907    -.032216
    end
    label values Category Category
    label def Category 1 "GCC", modify
    label def Category 2 "Maghreb", modify
    label def Category 3 "Mashreq", modify

    The command I am using is:

    Code:
    tw bar prevalencescore Category ||scatter regularintensity Category, yaxis(2)
    However, after adjusting the width to .5 the 3rd bar has disappeared, you can also see that my Categories are missing- the picture below-, I think this is due to the fact that I encoded the variable category because of a string variable is not allowed in the command above, moreover, the over() option is not allowed in a two-way option.

    Seeking your kind advice and help, much appreciated.

    Click image for larger version

Name:	Graph.png
Views:	1
Size:	36.6 KB
ID:	1516618

  • #2
    I don't know how you imported your images, but there is no good reason to show them so small.

    You're probably seeking extra options base(0) xla(1/3, valuelabel) as below


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long Category float(frequencyindex coverageratio prevalencescore regularintensity)
    1  .3943591  .4980086 2.0093305 .0003354162
    2  .3671874 .42085615 1.1860977   .01351625
    3 .26117173  .3459178  .9149907    -.032216
    end
    label values Category Category
    label def Category 1 "GCC", modify
    label def Category 2 "Maghreb", modify
    label def Category 3 "Mashreq", modify
    
    set scheme s1color 
    
    tw bar prevalencescore Category, barw(0.5) base(0) xla(1/3, valuelabel) || scatter regularintensity Category, yaxis(2)
    but the result (not shown here) is still mighty hard to decode.

    Consider using multidot as documented at https://www.statalist.org/forums/for...ailable-on-ssc

    Code:
     
    ssc install multidot 
    
    label var prev "prevalence score"
    label var reg "regular intensity"
    multidot prevalencescore regularintensity, over(Category) sort(Category) recast(bar) ysize(3)
    Click image for larger version

Name:	baranddot.png
Views:	1
Size:	16.1 KB
ID:	1516626

    Comment


    • #3
      Dear Nick,

      Thank you, much much appreciated, I wonder is it possible and doable to add two -I'd say "categories" namely (Category and Sector)- in a twoway graph with two axes, as in the picture below?
      It's straightforward in a bar graph (but without the scatter plot and 2nd axis, using the
      Code:
      over()
      option), however, I looked almost everywhere in every possible resource, but I couldn't add the Sector variable to the graph.
      Any suggestion is highly appreciated, kindly find below the data:
      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input long(Category Sector) str16 sector float(frequencyindex coverageratio prevalencescore regularintensity)
      1 2 "Manufcature"       .3943591  .4980086 2.0093305 .0003354162
      2 1 "Agri-Food"         .3671874 .42085615 1.1860977   .01351625
      3 3 "Natural-resource" .26117173  .3459178  .9149907    -.032216
      end
      label values Sector Sector
      label def Sector 1 "Agri-Food", modify
      label def Sector 2 "Manufcature", modify
      label def Sector 3 "Natural-resource", modify
      Thank you.
      Click image for larger version

Name:	Twoway bar and scatter plot.png
Views:	2
Size:	15.1 KB
ID:	1518475



      Attached Files

      Comment


      • #4
        the example misses the country-type dimension. Can you fix that? So to make your graph we need 9 observations: one for each industry/country-type combination. Your example data only contains data on each industry.
        ---------------------------------
        Maarten L. Buis
        University of Konstanz
        Department of history and sociology
        box 40
        78457 Konstanz
        Germany
        http://www.maartenbuis.nl
        ---------------------------------

        Comment


        • #5
          Your data example and your example graph don't agree. In your graph you have two measures and a two-way classification.

          For what it's worth, I'd fix the typo "Manufcature" to say "Manufactures"

          I'd present a better data example if you want a more focused answer.

          To anticipate a longer answer, the short answer is by().

          It's not a good tactic to claim that you looked almost everywhere in every possible resource, as reading -- or at least skimming -- the Graphics manual would show many examples of by().

          Comment


          • #6
            Thank you Maarten,

            I apologize for the mistake, kindly find below, the amended data:
            Code:
            * Example generated by -dataex-. To install: ssc install dataex
            clear
            input long(Gross_Sector Sub_Region) double(prevalencescore RI)
            1 1  616.6233219252691   .00805287946476932
            2 1 103.84568913706472  -.04165844460973322
            3 1 52.842822432364585  -.12745600092722825
            1 2  592.7568604616203   .10712371921062513
            2 2 105.54585948542157  .012068663501905651
            3 2  95.43356919410901    .4886945810713045
            1 3  539.7469596682854  -.06907297031325735
            2 3  88.69352011264756 -.042448093406349176
            3 3 109.41277531606961  -.08244470316961224
            end
            label values Gross_Sector Gross_Sector
            label def Gross_Sector 1 "Agri-Food", modify
            label def Gross_Sector 2 "Manufacture", modify
            label def Gross_Sector 3 "Natural-resources", modify
            label values Sub_Region Sub_Region
            label def Sub_Region 1 "GCC", modify
            label def Sub_Region 2 "Maghreb", modify
            label def Sub_Region 3 "Mashreq", modify

            Comment


            • #7
              Thank you, Nick,

              Sorry for the mistake, I thought I can build on the previous data
              I tried the
              Code:
              by()
              option, and it created three separated graphs. and I want them to be in a single graph.

              Comment


              • #8
                I am not recommending this graph, but you can do it:

                Code:
                twoway bar prev Sub_Region, by(Gross_Sector, cols(3) compact note("")) xlab(1/3, val) || scatter RI Sub_Region , yaxis(2)
                ---------------------------------
                Maarten L. Buis
                University of Konstanz
                Department of history and sociology
                box 40
                78457 Konstanz
                Germany
                http://www.maartenbuis.nl
                ---------------------------------

                Comment


                • #9
                  Thanks for the data example. Here is some technique for the bar chart. Fooling around to plot something with quite different units and values in the same space is not to my taste, so I leave that open.


                  Code:
                  twoway bar RI Sub_Region, by(Gross_Sector, row(1) note("")) scheme(s1color) xla(1/3, valuelabel tlength(0)) barw(0.7) bfcolor(green*0.2) blc(green) xtitle("") yla(0 "0" -0.2 0.2(0.2)0.6, format(%02.1f) ang(h))
                  Click image for larger version

Name:	rabih.png
Views:	1
Size:	21.5 KB
ID:	1518482

                  Comment


                  • #10
                    Note that further options as in the following play down the panel divisions.


                    Code:
                    twoway bar RI Sub_Region, by(Gross_Sector, compact row(1) note("")) scheme(s1color) xla(1/3, valuelabel tlength(0)) barw(0.7) bfcolor(green*0.2) blc(green) xtitle("") yla(0 "0" -0.2 0.2(0.2)0.6, format(%02.1f) ang(h)) subtitle(, fcolor(none) nobox nobexpand)

                    Comment

                    Working...
                    X