Announcement

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

  • graph hbar - bargap(#) and bar(#, fcolor(.)) do not work

    Dear all,

    My code is the following:
    Code:
    graph hbar (first) estimates, over(authors_num, descending label(labsize(vsmall)))  blabel(bar) stack  graphregion(margin(-40 2 2 2))   ylabel(0(20)210) scheme(s1color)
    My initial graph is horizontal green bars.

    I want to change the color of only the 3rd bar and reduce the interval between bars, so I use:
    Code:
    graph hbar (first) estimates, over(authors_num, descending label(labsize(vsmall)))  blabel(bar) stack  graphregion(margin(-40 2 2 2))   ylabel(0(20)210) scheme(s1color)  bar(3, fcolor(red)) bargap(0)
    Using bar(3, fcolor(red)) changes the original color of all bars to red, not only the 3rd bar.

    Using bargap(0) does not change anything in my graph.

    Using

    Code:
    graph hbar (first) estimates, over(authors_num, descending label(labsize(vsmall)))  blabel(bar) stack  graphregion(margin(-40 2 2 2))  ylabel(0(20)210) scheme(s1color)  ascategory asyvars bar(3, fcolor(red)) legend(off)
    give me a weird graph that is totaly different from what I want:
    Click image for larger version

Name:	graph2.png
Views:	1
Size:	7.5 KB
ID:	1712867


    Am I doing something wrong? can you help please?

  • #2
    To make progress, I think we need to see a data example:


    Code:
    dataex estimates authors_num  
    and indeed to know why you asked to stack bars any way.

    Comment


    • #3
      Nick Cox Thank you for your answer

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input double estimates float authors_num
         .3  1
        1.6  2
        1.8  3
        2.1  4
        8.7  5
         11  6
         15  7
      16.65  8
        139  9
        142 10
        160 11
        163 12
         20  7
        200  9
      end
      Yes sorry for the stack, it has no need here.
      Please use the following code:
      Code:
      graph hbar (first) estimates, over(authors_num, descending relabel(1 "Author 1" 2 "Author 2" 3 "Author 3" 4 "Author 4" 5 "Author 5" 6 "Author 6" 7 "Author 7" 8 "Author 8" 9 "Author 9" 10 "Author 10" 11 "Author 11" 12 "Author 12") label(labsize(vsmall)))  blabel(bar)    ylabel(0(20)210) scheme(s1color)

      Comment


      • #4
        Thanks for the example, but why are 7 and 9 repeated?

        Comment


        • #5
          Nick Cox, this is a dataset about papers and the findings in these papers. So in papers 7 and 9 there are 2 estimates in each one of them that I want to show, but I did not figure out how to do that yet, so I would appreciate it if you have any idea about that.
          Last edited by Marry Lee; 09 May 2023, 05:50.

          Comment


          • #6
            Fine.

            Code:
            scatter authors_num estimates, ysc(reverse) scheme(s1color) yla(1/12, grid ang(h)) ms(Dh)
            Consider also xsc(alt) for reasons given in https://journals.sagepub.com/doi/pdf...867X1201200314

            Click image for larger version

Name:	marry_lee.png
Views:	1
Size:	18.8 KB
ID:	1712890

            Comment


            • #7
              Nick Cox thank you so much, this is really helpful.

              Comment


              • #8
                Nick Cox, sorry this is me again. The solution with scatter is very good, but I just wanted to know whether it would have been possible to present the two values of estimates for the same paper if I have used graph hbar (for papers 7 and 9). No matter how much I think about it, I can't come up with a solution for that. I thought about creating another variable with the two additional values for 7 and 9, but it did not work. If you have any idea about that, can you please share it with me. Thank you!

                Comment


                • #9
                  My idea is that a bar chart is a very poor solution if you want in effect sometimes to show two bars in the same place, which is precisely why I didn't show you code for a bar chart.

                  If you really want a bar chart, twoway bar is more flexible than graph hbar, but again I don't reommend that.

                  Comment

                  Working...
                  X