Announcement

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

  • asyvars stack gap and color help

    Two things I need help with. I posted an image with and without the legend. You'll see that there are over 50 unique categories.

    1) I need all the categories to be the same width and I would also like there to be gaps if a group doesn't have a particular category. For instance, you'll notice some companies have more NAICS codes then others, I want the companies with less NAICS codes to have gaps to better show how they compare (if they lack a NAICS code that others have, it would have a gap).

    2). For some reason it looks like even though there are over 50 distinct categories the colors repeat. I'm using the default color scheme s2color and wondered why it repeats colors and if there was any way to ensure that there was a distinct color for each category. I know in theory the command I'm using (asyvars) does that but it doesn't appear to have different colors.

    Here is my code below:

    rename NAICSCode naics
    drop if naics == "-"
    destring naics, gen(NAICSCode)


    egen NaicsTotal = group(NAICSCode)
    egen n = group(NAICSCode)
    drop if FiscalYear != 2016

    #delimit ;

    graph hbar NaicsTotal, over(n) over(ParentVendor) asyvars stack


    title("NAICS Code", size(medium))
    subtitle(, size(small))

    ylabel(, grid noticks angle(horizontal))
    ytitle(" ")

    legend(off)

    ;
    #delimit cr

    Click image for larger version

Name:	no legend.png
Views:	3
Size:	47.2 KB
ID:	1411763 Click image for larger version

Name:	legend.png
Views:	1
Size:	61.9 KB
ID:	1411761
    Attached Files

  • #2
    #2 is easier: by default, as I recall, Stata cycles through 19 colours repeatedly. If you want more, you have to spell them out.

    Regardless of whether you get distinct colours, this design is, I have to say, doomed to failure.

    Here's your code simplified a bit. I don't understand why you have two variables the same. I don't have your data to check anything, but I think this would produce the same graph. I am puzzling by plotting the means of a category code; I can't see what this does usefully. That is what graph hbar does by default.

    Code:
    destring NAICSCode, ignore("-") replace 
    
    * aren't these two variables the same? 
    egen NaicsTotal = group(NAICSCode)
    egen n = group(NAICSCode)
    
    drop if FiscalYear != 2016
    
    graph hbar NaicsTotal, over(ParentVendor) asyvars stack     ///
    title("NAICS Code", size(medium)) subtitle(, size(small))   ///
    ylabel(, grid noticks angle(horizontal))  ytitle(" ") legend(off)
    It sounds like you are asking for a different design. tabplot from SJ offers one such. See https://www.statalist.org/forums/for...updated-on-ssc for an overview. Searching the forum for tabplot would lead to yet more examples.

    If you have access see http://www.stata-journal.com/article...article=gr0066

    If interested download the files from the Stata Journal website, regardless of whether the article is visible to you.

    Code:
    search tabplot, sj
    fires up a clickable download link gr066


    Code:
    . search tabplot, sj
    
    Search of official help files, FAQs, Examples, SJs, and STBs
    
    SJ-16-2 gr0066  . . . . . .  Speaking Stata: Multiple bar charts in table form
            (help tabplot if installed) . . . . . . . . . . . . . . . .  N. J. Cox
            Q2/16   SJ 16(2):491--510
            provides multiple bar charts in table form representing
            contingency tables for one, two, or three categorical variables

    Comment

    Working...
    X