Announcement

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

  • Graph bar: how to change "blabel" size

    Dear All,

    I'm producing a bar graph with data labels using the following code:
    Code:
    graph bar VAR1 if type=="A" | type=="B", ///
        by(type) over(year, label(labsize(vsmall))) ///
        blabel(bar,position(outside)) ///
        ylabel(, labsize(vsmall)) ///
        graphregion(color(white))
    The data labels (blabel) are too large and some are overlapped, I'm wondering how can I change blabels to smaller size?

    Any help is appreciated!

    (So sorry that I can't share the data, I'm not allowed to do so due to the data using restrictions...)

    Many thanks,
    Craig
    Last edited by Craig Yang; 20 Aug 2020, 23:49.

  • #2
    Sorry, stupid question. I've figured it out.

    Comment


    • #3
      Good that you solved your problem, but you raise two issues already discussed in the FAQ Advice everyone is asked to read before posting.

      First off, confidential data: we recognise that many people work with data they're not allowed to share, but we spell out what to do in this circumstance: invent data or use a standard dataset readable into anybody's Stata. See https://www.statalist.org/forums/help#stata

      Here is a simple analog[ue] of your problem with fake data. I am confident that graph region colo[u]r doesn't bear upon the solution.

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input float year str1 type float whatever
      2000 "A"  1
      2001 "A"  2
      2002 "A"  3
      2003 "A"  4
      2004 "A"  5
      2000 "B"  6
      2001 "B"  7
      2002 "B"  8
      2003 "B"  9
      2004 "B" 10
      end
      
      
      graph bar whatever,  by(type) over(year, label(labsize(vsmall)))   blabel(bar,position(outside)) ylabel(, labsize(vsmall))
      Second, Statalist is about answers as well as questions, and a forum, not a help line that happens to be in public. So, no matter how stupid you think your question, someone else is likely to have the same problem and some seeing this thread will want to know an answer. See 16.2 at https://www.statalist.org/forums/help#closure

      What you presumably found was a size() suboption.

      Code:
      graph bar whatever,  by(type) over(year, label(labsize(vsmall))) ///
          blabel(bar,position(outside)  size(large)) ylabel(, labsize(vsmall))
      There is more. I've seen numerous versions of this problem -- bar charts for time series data -- and although many people start with graph bar that is often a poor solution for time series because graph bar insists on label[l]ing each year. For 5 years as in my silly example that is fine. For 20 years already it is uncomfortable; for 200 years it would be ridiculous.

      Also, showing information on axes is good but making all your text
      vsmall is puzzling.

      I have a paper on this that I guess will appear in Stata Journal 20(4) around December 2020, which isn't much use to you now, but the main point is to switch to
      twoway bar.

      Here's a sample. My scheme is s1color.

      Code:
      twoway bar whatever year, color(blue*0.5) base(0) by(type, note("") legend(off)) barw(0.8) ///
      || scatter whatever year, ms(none) mla(whatever) mlabpos(12) yla(none) ysc(r(0 11)) xtitle("")

      Click image for larger version

Name:	whatever.png
Views:	1
Size:	19.0 KB
ID:	1569444


      Here as said showing every year is perfectly comfortable. But with say 20 years you would be more likely to want to show every 5 years or every 2 years. twoway bar is fine with that, whereas graph bar is not.

      Among other details, I zapped the x axis title "year". Our teachers were quite right to tell us to explain every axis, but any reader who needs to be told that 2000 to 2004 means "year" needs other help. (Oh, and the ticks are not really needed either.)

      Comment


      • #4
        Hi Nick,

        Thank you very much for your help and all the clear explaining. It is very helpful.

        You are right, for my question, the
        size()
        suboption is the solution. I make the text
        vsmall
        because for some graphs I need to show more than 6 types on one graph, the labels will overlap if the text size is too large.

        Below is the code that I use:
        Code:
        graph bar VAR1 if type==”A” | type==”B”, ///
                    by(type) over(year, label(labsize(vsmall))) ///
                    blabel(bar,position(outside) size(tiny)) ///
                    ylabel(, labsize(tiny))
        graph export "Graph1.png", replace
        Best,
        Craig

        Comment


        • #5
          My unsurprising advice is to make your graphs readable. Even supposed professionals writing with reputable publishers include graphs that can't be read, but few practices seem more pointless.

          The Tip referred in #4 won't appear until 21(1), around March.


          Comment


          • #6
            Hi Nick,

            Thank you for your advice! Much appreciated.

            Best,
            Craig

            Comment


            • #7
              I also recommend experimenting with vertically-aligned bar labels: orientation(vertical) in
              Code:
              blabel(bar, orientation(vertical) size(vsmall))

              Comment


              • #8
                #7 Please, no vertical labels unless all other choices are worse. Giraffe graphics! Let's have graphics for people, not giraffes, whose life is based on moving their heads constantly.

                As said the problem often is using graph bar when twoway bar is a better idea, but the paper alluded to in #4 and #5 gives other ideas and is accessible at

                https://journals.sagepub.com/doi/pdf...6867X211000032

                Comment


                • #9
                  Here is an example of why I found vertically-aligned bar labels useful, in one case:

                  Click image for larger version

Name:	Occ_freq.png
Views:	1
Size:	54.5 KB
ID:	1711588

                  Comment


                  • #10
                    Indeed. This is one of many cases in which experienced people are likely to give contradictory advice. If you put the numbers in a table too, somebody will object that the table adds nothing to the graph. If you give a table only, someone will ask for a graph. If you rotated the graph so that the time axis was vertical, plenty of people would think that weird.

                    If I were reviewing or examining this formally, I would advise against:the text labels too (does anyone really care that one value was 99702 in contrast to any other number close to 100000?) and against labelling every year on the time axis, but all I am doing is commenting here. .(I would also suggesting trying a line graph.)

                    Comment

                    Working...
                    X