Announcement

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

  • How can I edit the space between a bars in a twoway graph?

    Hi!
    How can I edit the space between a bars in a twoway graph?
    I'm using this, but don't know how to edit the space in between:

    twoway (bar Aprobacióndelgobierno PresentaAC, barw(0.25)) || (rcap yu y1 PresentaAC), legend(order(1 "Aprobación Promedio" 2 "IC")) xlabel(0 "No" 1 "Sí") ytitle(`"Aprobación de Gobierno (%)"') ylabel(, angle(horizontal))

    Thank you!

  • #2
    Increase the bar width, and the spacing will decrease, and vice versa.

    Comment


    • #3
      Can I do it without changing the bar width? It is too wide

      Comment


      • #4
        I don’t know another way to do it but why do you think you need one? The x axis shows 0 and 1 so try any value of barw() between say 0.5 and 0.9.

        Comment


        • #5
          Click image for larger version

Name:	1_1_Apro_y_presenta_o_no_AC_con_test.png
Views:	1
Size:	32.8 KB
ID:	1756243

          If I do it more wide is to big
          Click image for larger version

Name:	wide.png
Views:	1
Size:	30.9 KB
ID:	1756244

          Comment


          • #6
            Choose any number that gets the desired result. Sorry, but what's the difficulty here? Let me try Spanish:

            entre 0,5 y 0,9

            Comment


            • #7
              Effect bars with error bars (e.g. confidence intervals) are often known (negatively) as dynamite plots, detonator plots, or plunger plots -- and perhaps other names too.

              For propaganda against their use, see e.g.

              https://biostat.app.vumc.org/wiki/pu...de/Poster3.pdf

              https://simplystatistics.org/posts/2...lots-must-die/

              https://warwick.ac.uk/fac/sci/wdsi/e...es/plunger.pdf


              Some technique specific to your question:

              Code:
              sysuse auto, clear
              
              bysort foreign: gen count = _N
              
              levelsof count, local(levels)
              
              forval j = 1/9 {
                  local w : di %02.1f `j'/10
                  twoway bar count foreign, base(0) barw(`w') subtitle(bar width `w') ///
                  yla(0 `levels', glc(red) glp(solid)) name(G`j', replace) xla(0 "Domestic" 1 "Foreign")
                  local graphs `graphs' G`j'
              }
              
              graph combine `graphs'
              Click image for larger version

Name:	bar_width.png
Views:	1
Size:	79.2 KB
ID:	1756274

              Last edited by Nick Cox; 15 Jun 2024, 01:30.

              Comment


              • #8
                Thank you Nick! Do you know how can I replace the bars (that shows the average for each case) with red dots?

                This is my code:
                *Box plot with CI
                collapse (mean) Aprobacióndelgobierno (semean) sd = Aprobacióndelgobierno, by(PresentaAC)
                gen yu = Aprobacióndelgobierno + 1.96*sd
                gen y1 = Aprobacióndelgobierno - 1.96*sd

                twoway (bar Aprobacióndelgobierno PresentaAC, barw(0.15)) || (rcap yu y1 PresentaAC), legend(order(1 "Aprobación Promedio" 2 "IC")) xlabel(0 "No" 1 "Sí") ytitle(`"Aprobación de Gobierno (%)"') ylabel(, angle(horizontal))
                graph export 1_1_Apro_y_presenta_o_no_AC_con_test.png, replace

                Comment


                • #9
                  #8 is a duplicate post. Please follow https://www.statalist.org/forums/for...-show-averages if interested.

                  Comment

                  Working...
                  X