Announcement

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

  • #16
    Once again, you are reporting a problem without reporting the exact code or the exact error report.

    Note, however, that bargap() is an option of graph bar. You are not using that; you are using twoway bar. Bars aside, these are different commands without the exact same syntax.

    Think about the code last seen here.

    A bar of width 0.3 could be drawn with centre 0.15 of the way from each integer point. Here's his friend:



    Now find a smart 7-year old. (I am out of touch with smart 7-year olds; perhaps you need a smart 9-year old.)

    She will tell you that a bar of width 0.4 could be drawn with centre 0.2 of the way from each integer point, and so forth. Here's another friend:



    Moral: To vary the bar widths, adjust the constants in the code.

    Comment


    • #17
      I've faithfully followed the instructions you gave me yesterday, and I am not changing the bar widths. Indeed the only thing I did was experiment on changing the constants to 0.14 to get a slightly smaller size for the bars. But my real problem has to do with the gaps in between the pair of bars, that is, the gap between, say, JPN and DEN, and so on. I do not have much space since I need to combine two graphs together so that I could fit all the 10 graphs that I have. I've looked everywhere, and I can't find any instructions of how to reduce the gaps between the set of bars. Again, I'm sorry for being unclear.

      Comment


      • #18
        I think I've answered this already, except that if you are running out of space I would abandon the format of bars side by side.

        I am not sure that this graph makes much sense with the data you posted but it may not be your real data any way.

        Code:
         
        clear
        input str6 ctry start end ave
        "CHN"  1 0 5
        "DEN"  59 63 35
        "ESP"  16 10 20
        "JPN" 639 229 197
        "MYS"  1 1 1
        "PH"  2 1 2
        "US" 56 1 13
        "ALL"  57 0.5 14
        end
        gen work = -ave
        egen xaxis = group(work ctry)
        labmask xaxis, val(ctry)
        
        twoway pcarrow xaxis start xaxis end  ///
        || scatter xaxis ave, yla(1/8, val noticks) xtitle(whatever) yla(, val ang(h) noticks)  ///  
        legend(off) ytitle("") ysc(reverse)

        Comment


        • #19
          Code:
           graph combine g1.gph g2.gph g3.gph g4.gph g5.gph g6.gph g7.gph g8.gph g9.gph g10.gph, row(5) col(2)
          after saving each graph separately with
          Code:
           graph save
          Then export the graph using the desired format, such as emf wmf and so on:
          Code:
           graph export combinedgraph.emf

          Comment


          • #20
            This the dofile you provided me yesterday. I followed it and I'm OK with the bar widths (between start and end), but not with the gaps in between the bar pairs(between countries). I need to reduce them. I've tried looking all over for instructions but just couldn't find any.




            clear input str6 ctry start end ave "CHN" 1 0 5 "DEN" 59 63 35 "ESP" 16 10 20 "JPN" 639 229 197 "MYS" 1 1 1 "PH" 2 1 2 "US" 56 1 13 "ALL" 57 0.5 14 end gen work = -ave egen xaxis = group(work ctry) labmask xaxis, val(ctry) gen x1 = xa - 0.15 gen x2 = xa + 0.15 scatter ave xaxis, ms(none) /// || bar start x1, barw(0.3) /// || bar end x2, barw(0.3)|| /// scatter ave xaxis, xla(1/8, val noticks) ytitle(whatever) yla(, ang(h)) /// legend(off) xtitle("")

            Comment


            • #21
              sorry about that...

              clear input str6 ctry start end ave
              "CHN" 1 0 5
              "DEN" 59 63 35
              "ESP" 16 10 20
              "JPN" 639 229 197
              "MYS" 1 1 1
              "PH" 2 1 2
              "US" 56 1 13
              "ALL" 57 0.5 14
              end
              gen work = -ave
              egen xaxis = group(work ctry)
              labmask xaxis, val(ctry)
              gen x1 = xa - 0.15
              gen x2 = xa + 0.15
              scatter ave xaxis, ms(none) ///
              || bar start x1, barw(0.3) ///
              || bar end x2, barw(0.3)|| ///
              scatter ave xaxis, xla(1/8, val noticks) ytitle(whatever) yla(, ang(h)) ///
              legend(off) xtitle("")

              Comment


              • #22
                Already explained in #16, or else I don't understand what you mean. 0.15 and 0.3 are the constants to change, but they just make the bars bigger.

                Comment


                • #23
                  Originally posted by annettepelkmans View Post
                  I do not have much space since I need to combine two graphs together so that I could fit all the 10 graphs that I have.
                  Maybe a narrower graph helps. You can control this with the xsize() option.
                  Code:
                  clear
                  input str6 ctry start end ave
                  "CHN" 1 0 5
                  "DEN" 59 63 35
                  "ESP" 16 10 20
                  "JPN" 639 229 197
                  "MYS" 1 1 1
                  "PH" 2 1 2
                  "US" 56 1 13
                  "ALL" 57 0.5 14
                  end
                  gen work = -ave
                  egen xaxis = group(work ctry)
                  labmask xaxis, val(ctry)
                  gen x1 = xaxis - 0.15
                  gen x2 = xaxis + 0.15
                  scatter ave xaxis, ms(none) ///
                  || bar start x1, barw(0.3) ///
                  || bar end x2, barw(0.3)|| ///
                  scatter ave xaxis, xla(1/8, val noticks) ytitle(whatever) yla(, ang(h)) ///
                  legend(off) xtitle("") xsize(3)
                  Could you please use CODE tags, as explained in section 12 of the FAQ?

                  Comment


                  • #24
                    My problem is not the gaps between the pair of bars ("start" and "end"), but the gaps between the countries. So I am not trying to change the gaps by manipulating the constants (as you said, they just make the bars bigger), but what I need is a smaller gap between JPN, DEN, ESP, CHN, etc… I do understand what you mean with the constants, Prof. Cox, but I'm trying to figure out how to minimise the distance in between the countries. Maybe, this is just impossible. The bargap option is wrong, because that pertains to a graph not a two-way graph, as you said, but it also does not fix the gaps between the group of bars. I can perhaps make the graph narrower, but it looks disproportional with the relatively big gaps between the countries.
                    So in the graph in #13, what I need is for the orange bar of DEN to be a bit closer to the blue bar of JPN.
                    Last edited by annettepelkmans; 09 Jul 2015, 13:20.

                    Comment


                    • #25
                      I find it difficult to understand what you are trying to achieve. The only way to minimize the distance between countries is to reduce the width of the graph (post #23) or to add more countries. If you want to reduce the distance between the bars for each country then see post #16, where Nick explained what you have to do. I will go one step further than Nick and provide example code, with 0.15 changed to 0.25 and 0.3 to 0.5.
                      Code:
                      clear
                      input str6 ctry start end ave
                      "CHN" 1 0 5
                      "DEN" 59 63 35
                      "ESP" 16 10 20
                      "JPN" 639 229 197
                      "MYS" 1 1 1
                      "PH" 2 1 2
                      "US" 56 1 13
                      "ALL" 57 0.5 14
                      end
                      gen work = -ave
                      egen xaxis = group(work ctry)
                      labmask xaxis, val(ctry)
                      gen x1 = xaxis - 0.25
                      gen x2 = xaxis + 0.25
                      scatter ave xaxis, ms(none) ///
                      || bar start x1, barw(0.5) ///
                      || bar end x2, barw(0.5)|| ///
                      scatter ave xaxis, xla(1/8, val noticks) ytitle(whatever) yla(, ang(h)) ///
                      legend(off) xtitle("")

                      Comment


                      • #26
                        Friedrich, thanks for the help. It took me a while understanding my problem myself! I now realised that I should make the bar width bigger (instead of smaller, as what I have been doing), and then reduce the width of the y axis. Thanks for bearing with me.

                        Comment


                        • #27
                          Would you mind sharing your solution? Thanks.

                          Comment

                          Working...
                          X