Announcement

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

  • Axis options for box plot - how can I reduce number of labels on the x axis?

    Hi,
    I have made boxplots of variable inc with two subcategories (year and cat) where year goes from 1995-2014.
    graph box inc , over(year, label(angle(vertical) labsize(tiny))) over(cat)

    I have managed to make the labels for year very small - so they can fit, but they are virtually illegible, so I would like to just have a label every 5th year.
    I can do this in other types of plot with e.g. ylabel(1995(5)2015)

    But cannot find any way of doing it for box plots. I have looked at all the documentation for Stata and searched on google, but to no avail.
    any advice would be greatly appreciated

    Rosemary




  • #2
    Two suggestions:

    1. Consider making a graph with horizontal boxes (graph hbox); it may be an advantage.
    2. Set value labels on years, "-" for most years, but drop it for selected years.

    How about this:


    Code:
    foreach Y of numlist 1995/2014 {
        label define year `Y' "-" , modify
    }
    
    foreach Y of numlist 1995(5)2010 2014 {
        label define year `Y' "" , modify
    }
    label values year year
    
    label define cat 1 "The first category" 2 "The second category"
    label values cat cat
    
    graph hbox inc , over(year, label(angle(horizontal))) ///
        over(cat, label(angle(vertical))) xsize(3) ysize(6)

    Comment


    • #3
      My idea is loosely similar to Svend's. Use value labels to blank out what you don't want.

      Code:
      clear 
      set obs 126 
      egen year = seq(), block(6) from(1990) to(2010)
      set seed 2803
      gen y = exp(rnormal())
      graph box y, over(year)
      
      forval y = 1990/2010 {
          if mod(`y', 5) {
              label def ylbl `y' `"{c 0xa0}"', add 
          }
      }
      
      label val year ylbl 
      
      label li ylbl 
      
      graph box y, over(year)
      The SMCL directive prints a character that looks like a space, but isn't.

      Comment


      • #4
        Many thanks Svend and Nick. Both these solutions work. I hadn't realised that you could use the label command.

        Comment


        • #5
          Good. It's perhaps important to explain the viewpoint here. graph box, graph hbox, graph bar, graph hbar, etc. with over() options are written as if over() specifies a categorical variable which the researcher cares about, which implies wanting to see all the category values or labels. Your problem is naturally one in which the graph designer can reasonably expect that the graph reader doesn't need to see all the values (indeed they occlude each other), but the result is that you have to subvert the syntax somehow.

          Comment

          Working...
          X