Announcement

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

  • Bar chart with intervals

    I'm plotting the following bar chart where "date" contains around 100 observations thus I would like to reduce the number of labels appearing in my x-axis. Is there any way of plotting all the observations but showing the label of 1 out 5 in the x-axis. I've been trying to introduce something like this in the label option (1(5)100) but it didn't work.

    Code:
    graph bar (count) count_m count_f, over(date, label(labsize(vsmall) )) stack

  • #2
    This code could work.
    Code:
     
     graph bar (count) count_m count_f, over(date, label(labsize(vsmall)) xlabel(#5)) stack

    Comment


    • #3
      I don't think xlabel is allowed in a bar graph. Indeed the error says "option xlabel() not allowed" when I run it

      Comment


      • #4
        The question in #1 arises quite often and indeed arose yesterday: https://www.statalist.org/forums/for...-bar-over-date

        There are various work-arounds for this, many but not all are covered in a Tip to appear shortly in Stata Journal 21(1). The work-arounds I discuss don't include #2, making lots of labels very small.

        For a bar chart with many dates there is no good work-around with graph bar, but positively a much better solution of switching to twoway bar as detailed in the linked thread.

        For daily data lasting 100 days I would consider labels once per week. The variable names in #1 suggest counts of males and females and so perhaps a medical application. Many of us have seen graphs arising from the pandemic with weekly irregularities arising from lower case reports or activity at weekends.

        Conversely if your data are for weekdays only then axis labels every fifth day could be exactly right and indeed might reflect use of a business calendar.

        Comment


        • #5
          #4 is right. xlabel() is not allowed with graph bar. In any case "I want around 5 labels on an axis" is only exceptionally the same as "I want only every 5th label".

          Comment


          • #6
            More discussion published (today) at https://journals.sagepub.com/doi/pdf...6867X211000032

            Comment


            • #7
              Thanks Nick! Indeed "twoway" is a great alternative!

              Comment

              Working...
              X