Announcement

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

  • Combining bar graphs

    I am trying to combine bar graphs of different variables in one figure but the y-axis is distorted across the variables. I have tried a number of different scaling option but can't get a common axis for bar graphs with different variables.

  • #2
    Hello John,

    Welcome to the Stata Forum.

    I kindly suggest you post commands and graph, according to the specifications provided in the FAQ.

    This is the best way to improve chances of getting insightul replies.

    Best,

    Marcos
    Best regards,

    Marcos

    Comment


    • #3
      Okay thanks. Here are my commands for the graphs and comibine, thanks again.

      graph bar naturalization_percentage expel_percentage ,over( parent_origin,relabel(1 "Neither is citizen" 2 "Mother is citizen" 3 "Father is citizen")) bar(1, fcolor(black) lcolor(none)) bar(2, fcolor(gray) lcolor(none)) blabel(bar, position(inside) color(white) format(%9.2f)) ylabel(0(10)60, angle(0)) legend(order(1 "Frequency of support for naturalization" 2 "Frequency of support for deportation") cols(1)) name(figure2a,replace)

      graph bar naturalization_percentage expel_percentage if female_resp==1 ,over( parent_origin,relabel(1 "Neither is citizen" 2 "Mother is citizen" 3 "Father is citizen")) bar(1, fcolor(black) lcolor(none)) bar(2, fcolor(gray) lcolor(none)) blabel(bar, position(inside) color(white) format(%9.2f)) ylabel(0(10)60, angle(0)) legend(order(1 "Frequency of support for naturalization" 2 "Frequency of support for deportation") cols(1)) note(Note: Women respondents only, pos(6)) name(figure2b,replace)

      graph bar naturalization_percentage expel_percentage ,over( years_in_country ,relabel(1 "5 years" 2 "10 years" 3 "20 years")) bar(1, fcolor(black) lcolor(none)) bar(2, fcolor(gray) lcolor(none)) blabel(bar, position(inside) color(white) format(%9.2f)) ylabel(0(10)60, angle(0)) legend(order(1 "Frequency of support for naturalization" 2 "Frequency of support for deportation") cols(1)) name(figure2c,replace)

      graph combine figure2a figure2b figure2c,cols(1)


      Comment


      • #4
        Here is what the graph looks like
        Graph example.gph

        Comment


        • #5
          Hello John, when I wrote you may probably get insightful advice if you post a message "according to the specifications provided in the FAQ", I really meant it.

          Please take a look at FAQ.

          Just to summarize what is demanded:

          Please use CODE delimiters or the user-written dataex so as to share a short example of the data, plus the commands and output. You may find instructions in the topic 12.1.

          Please share the graphics under .png , according to the recommendations written in topic 12,4.

          There, by the way, there is a specific instruction NOT to post gph files:

          Please do not post .gph files, as they can't be read without flipping back and forth between Stata and the forum software, thus making your posts much more difficult to follow.
          Thank you.

          Best,

          Marcos
          Last edited by Marcos Almeida; 21 Oct 2016, 05:29.
          Best regards,

          Marcos

          Comment


          • #6
            I support Marcos here, but add that while we do make several requests of members in the FAQ Advice, we do so with good and stated reasons. The aim all along is make your questions easier to understand and to answer, and more correctly and more quickly.

            Your graph is readable with the disadvantage noted and it makes evident that working with graph combine may just be asking how to go further in the wrong direction. You need different graph syntax and possibly a diferent data structure before that. But a single Stata graph is possible in the first instance.

            You just need to give us a data example. Again, http://www.statalist.org/forums/help explains how.

            The thread http://www.statalist.org/forums/foru...ady-calculated is an example of how a single graph works even where there 4 variables in total. It's not always at all easy to think the data structure and syntax for a complicated graph, it's often possible.
            Last edited by Nick Cox; 21 Oct 2016, 05:50.

            Comment


            • #7
              Sorry about that. Here is the graph with the y-axes that are distorted.


              Click image for larger version

Name:	Graph.png
Views:	1
Size:	71.1 KB
ID:	1361184

              Comment


              • #8
                Thanks for the visible graph; otherwise same remarks as before. No data details from you imply no code comments from us.

                So much space here is used for the repeated legend that little is left for other stuff.

                If the second panel is women only, is the first panel men and women or men? Your code in #3 seems to imply (a) is men and women (b) is women. It's your project, but I can't easily think that through. I'd expect (a) men (b) women as easier to think about it.
                Last edited by Nick Cox; 21 Oct 2016, 08:46.

                Comment


                • #9
                  Thanks Nick. Here are the codes I am using

                  Code:
                  graph bar naturalization_percentage expel_percentage ,over( parent_origin,relabel(1 "Neither is citizen" 2 "Mother is citizen" 3 "Father is citizen")) bar(1, fcolor(black) lcolor(none)) bar(2, fcolor(gray) lcolor(none)) blabel(bar, position(inside) color(white) format(%9.2f)) ylabel(0(10)60, angle(0))  legend(order(1 "Frequency of support for naturalization" 2 "Frequency of support for deportation") cols(1)) name(figure2a,replace)
                  Code:
                  graph bar naturalization_percentage expel_percentage if female_resp==1 ,over( parent_origin,relabel(1 "Neither is citizen" 2 "Mother is citizen" 3 "Father is citizen")) bar(1, fcolor(black) lcolor(none)) bar(2, fcolor(gray) lcolor(none)) blabel(bar, position(inside) color(white) format(%9.2f))  ylabel(0(10)60, angle(0))  legend(order(1 "Frequency of support for naturalization" 2 "Frequency of support for deportation") cols(1))  note(Note: Women respondents only, pos(6)) name(figure2b,replace)
                  Code:
                  graph bar naturalization_percentage expel_percentage ,over( years_in_country ,relabel(1 "5 years" 2 "10 years" 3 "20 years")) bar(1, fcolor(black) lcolor(none)) bar(2, fcolor(gray) lcolor(none)) blabel(bar, position(inside) color(white) format(%9.2f)) ylabel(0(10)60, angle(0))   legend(order(1 "Frequency of support for naturalization" 2 "Frequency of support for deportation") cols(1)) name(figure2c,replace)

                  Comment


                  • #10
                    Also, the first panel includes all respondents (men and women) and the second women only. Then the third panel is a different variable, namely the length of time living in the country.

                    Comment


                    • #11
                      Combining the graphs with grc1leg (net install grc1leg, from(http://www.stata.com/users/vwiggins)) rather than -gr combine- put a single legend below the three graphs (specify that you only want one column). You might also consider simply increasing the vertical size of the combined graph using the -yxize- option or following up -grc1leg- with -gr display, ysize(8)-. The 8 says you want a graph that is 8 inches tall. A combination of both of those could get you closer to what you're hoping for.

                      Lance

                      Comment


                      • #12
                        Marcos asked for a data example in #5 and I repeated the request in #6 and #8. Your choice, but I see no encouragement to work further at this without one.

                        Any qualms about sensitivity and confidentiality are already answered in the FAQ Advice. Invent an example with the same structure if need be.

                        grc1leg is a useful and smart program but getting the graph right in the first place is better.

                        Comment


                        • #13
                          Thanks Lance and Nick. That helps a lot!

                          Comment


                          • #14
                            how do I have a common y-label instead of suppressing all. I want the race to be displayed only in the first graph.

                            use http://www.stata-press.com/data/r14/nlswork

                            graph hbar tenure hours wks_work if age < 16, ///
                            over(race, label(labstyle()) ) ///
                            by(age, style(combine) row(1) norescale edgelabel iylabel noiytitle iytick noiyaxes) ///
                            legend(label (1 "tenure") label (2 "hours") label (3 "wks_work") row(1)) ///
                            ysize(2) name(a, replace)
                            Click image for larger version

Name:	aa.png
Views:	4
Size:	73.0 KB
ID:	1641826

                            Comment


                            • #15
                              #14 is a duplicate post. See https://www.statalist.org/forums/for...-x-axis-labels for comment.

                              Comment

                              Working...
                              X