Announcement

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

  • Replicating Bar Graph From Article (Flors-Mas 2021)

    To whomever is interested. I am trying to replicate the following bar graph I obtained from an article (Flors-Mas 2021). As you can see, this is a bar graph whose categories are distributed across different values. I was wondering how to replicated using the data used in the article which I can also attach to this post if need be. I am currently trying to replicate the aforementioned graph, but there are so many options that I don't even know where to begin.

    Click image for larger version

Name:	Flors-Mas graph.png
Views:	2
Size:	183.3 KB
ID:	1765229

    Attached Files

  • #2
    Please see FAQ Advice #12 about not attaching ..dta files (thanks). The version of the data here should be close enough to discuss technique.

    I don't think that display is especially attractive. The use of a legend is always at best a necessary evil. There are far too many axis labels.

    This is the best I could come up with using tabplot from the Stata Journal. It's reluctant to plot bars of height 0 -- or perhaps willing, but unable. If you wanted to see text of 0.0 for the zero, fudge the data value to say 1e-9. %2.1fc should get you commas as decimal points.

    This is a challenge to others to produce something better.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(var1 var2 percent)
    1 1  1.1
    2 1    0 
    3 1 47.5
    4 1 49.4
    1 2  2.3
    2 2  1.5
    3 2 52.8
    4 2 42.7
    1 3  4.6
    2 3  2.9
    3 3 59.1
    4 3 32.5
    end
    label values var1 var1
    label def var1 1 "Catalan", modify
    label def var1 2 `" "Catalan and" "Castilian" "', modify
    label def var1 3 "Castilian", modify
    label def var1 4 "Others", modify
    label values var2 var2
    label def var2 1 "first", modify
    label def var2 2 "identification", modify
    label def var2 3 "habitual", modify
    
    tabplot var1 var2 [iw=percent], showval(format(%2.1f)) separate(var1) xtitle("") ytitle("") name(G1, replace)
    Click image for larger version

Name:	catalanetc.png
Views:	1
Size:	36.7 KB
ID:	1765264

    Comment


    • #3
      Here's another take.

      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input float(var1 var2 percent)
      1 1  1.1
      2 1    0 
      3 1 47.5
      4 1 49.4
      1 2  2.3
      2 2  1.5
      3 2 52.8
      4 2 42.7
      1 3  4.6
      2 3  2.9
      3 3 59.1
      4 3 32.5
      end
      label values var1 var1
      label def var1 1 "Catalan", modify
      label def var1 2 `" "Catalan and" "Castilian" "', modify
      label def var1 3 "Castilian", modify
      label def var1 4 "Others", modify
      label values var2 var2
      label def var2 1 "first", modify
      label def var2 2 "identification", modify
      label def var2 3 "habitual", modify
      
      twoway bar percent var2, barw(0.7) xla(1/3, tlc(none) valuelabel) ///
      || scatter percent var2, ms(none) mla(percent) mlabpos(12) ///
      by(var1, row(2) note("") legend(off)) xtitle("") ysc(r(0 65))  name(G2, replace)
      Click image for larger version

Name:	catalanetc2.png
Views:	1
Size:	74.8 KB
ID:	1765297

      Comment


      • #4
        The incomplete reference appears to expand to

        Flors-Mas, A. (2021). Immigration and Languages in Catalonia: From Policies to Results. Journal of Iberian and Latin American Research, 27(2), 368–385. https://doi.org/10.1080/13260219.2021.1994712

        which is behind a paywall so far as I am concerned.

        https://www.statalist.org/forums/help#references explains our policy on giving full references.

        Comment


        • #5
          Here is an attempt to create the original graph/table combination. It is not intended to improve on the original design.

          Code:
          clear
          input float(var1 var2 percent)
          1 1  1.1
          2 1    0
          3 1 47.5
          4 1 49.4
          1 2  2.3
          2 2  1.5
          3 2 52.8
          4 2 42.7
          1 3  4.6
          2 3  2.9
          3 3 59.1
          4 3 32.5
          end
          label values var1 var1
          label def var1 1 "Catalan", modify
          label def var1 2 `" "Catalan and" "Castilian" "', modify
          label def var1 3 "Castilian", modify
          label def var1 4 "Others", modify
          label values var2 var2
          label def var2 1 "first", modify
          label def var2 2 "identification", modify
          label def var2 3 "habitual", modify
          
          gen x = (var1 -1) * 4 + var2 -1
          
          twoway bar percent x if var2 == 1 ||                   ///
                 bar percent x if var2 == 2 ||                   ///
                 bar percent x if var2 == 3,                     ///
                 xlabel(1 "Catalan"                              ///
                        5 `""Catalan and" "Castilian""'          ///
                        9 "Castilian"                            ///
                        13 "Other", notick)                      ///
                 legend(off)                                     ///
                 xtitle(" ", height(1.5cm))                      /// add more room below
                 l1title(" ", height(1cm))                       /// add more room left
                 ylabel(0(20)60)  yscale(range(0 60))            ///
                 text(-13  1 "`:display %5.1f `=percent[1]''"  ) ///
                 text(-16  1 "`:display %5.1f `=percent[5]''"  ) ///
                 text(-19  1 "`:display %5.1f `=percent[9]''"  ) ///
                 text(-13  5 "`:display %5.1f `=percent[2]''"  ) ///
                 text(-16  5 "`:display %5.1f `=percent[6]''"  ) ///
                 text(-19  5 "`:display %5.1f `=percent[10]''" ) ///
                 text(-13  9 "`:display %5.1f `=percent[3]''"  ) ///
                 text(-16  9 "`:display %5.1f `=percent[7]''"  ) ///
                 text(-19  9 "`:display %5.1f `=percent[11]''" ) ///
                 text(-13 13 "`:display %5.1f `=percent[4]''"  ) ///
                 text(-16 13 "`:display %5.1f `=percent[8]''"  ) ///
                 text(-19 13 "`:display %5.1f `=percent[12]''" ) ///
                 text(-13 -2 "first"         ,placement(e))      ///
                 text(-16 -2 "identification",placement(e))      ///
                 text(-19 -2 "habitual"      ,placement(e))      ///
                 text(-13 -2.5 "■", color(stc1))                 ///
                 text(-16 -2.5 "■", color(stc2))                 ///
                 text(-19 -2.5 "■", color(stc3))
          Click image for larger version

Name:	Graph.png
Views:	1
Size:	66.9 KB
ID:	1765315
          ---------------------------------
          Maarten L. Buis
          University of Konstanz
          Department of history and sociology
          box 40
          78457 Konstanz
          Germany
          http://www.maartenbuis.nl
          ---------------------------------

          Comment


          • #6
            For a multi-colour version of #3

            Code:
            separate percent, by(var1) 
            
            set scheme stcolor 
            
            twoway bar percent? var2, barw(0.7 ..) xla(1/3, tlc(none) valuelabel) ///
            || scatter percent var2, ms(none) mla(percent) mlabpos(12) ///
            by(var1, row(2) note("") legend(off)) ytitle("percent") xtitle("") ysc(r(0 65))  name(G2, replace)

            Comment


            • #7
              Yet another take (assuming data as in #2)

              Code:
               
               separate percent, by(var1)  
              
               graph hbar percent?, over(var2) over(var1) nofill legend(off) blabel(bar) ysc(off) t1title(percent)
              Click image for larger version

Name:	catalanetc3.png
Views:	1
Size:	32.9 KB
ID:	1765359


              Comment

              Working...
              X