Announcement

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

  • Altering x-axis labels in stacked bar chart

    Hello,
    I am trying to create a stacked bar chart (categories: vaccinated and unvaccinated) where each bar represents a day over an influenza season (i.e., a standard epicurve). Because I cannot find options to 'stack' a histogram in Stata, I am using a stacked bar chart ('graph bar'). I am running Stata SE 15 on a Mac and simultaneously Stata MP 15.1 through a virtual Windows desktop.

    I am using the following code:
    Code:
    graph bar unvax_cases vax_cases, over(specimen_date) stack
    I am fairly close to what I want, but have an x-axis label problem (see attached).
    Click image for larger version

Name:	image_21778.jpg
Views:	1
Size:	427.1 KB
ID:	1599467
    I know there is an option to recode the values on the x-axis, but there are thousands here, and I don't want them. How can I 1) recode the value labels and 2) simultaneously reduce the number that is being shown (for example, show only the month or the year), while still showing the data by day?

    The usual pre-emptive apologies apply to those of us for whom an answer is obvious. I am grateful for your suggestions and help.
    Maria
    Last edited by Maria Sundaram; 23 Mar 2021, 14:34.

  • #2
    I don't think this is obvious at all. There is a lengthy Tip in press for Stata Journal 21(1) ruminating in this problem area, which will appear soon, that doesn't help at this instant, and in any case my suggestion is direct.

    Code:
    gen total = unvax_cases + vax_cases 
    
    twoway bar unvax_cases specimen_date || rbar unvax_cases total specimen_date, legend(order(1 "whatever" 2 "fits"))
    Now you can pick axis labels according to taste,

    Comment


    • #3
      Thank you so, so much—this fix worked perfectly. I’m excited to read the Tip as well. Thank you.

      Comment


      • #4
        Now published at https://journals.sagepub.com/doi/pdf...6867X211000032

        Comment

        Working...
        X