Announcement

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

  • -Coefplot- Rotating Graph

    Hi,
    I installed -coefplot-, created by Nick Cox and I am having some trouble manipulating the graph. I would like to rotate this graph so that it is horizontal rather than vertical. I can accomplish this by just rotating the image itself, but then the y-axis is on the right size and "County Name" is written upside down. How should I change my code to rotate the graph correctly?
    Thank you!
    Code:
    catplot name, var1opts(sort(1)) ysize(10) ytitle("Number of Wildfires")
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	37.4 KB
ID:	1497370


  • #2
    coefplot (Stata Journal) is nothing to do with me. Fix the thread title if you can.

    catplot (SSC) sounds more familiar.

    This shows minimal technique, but be warned. The result in your case will predictably be horrible.

    Code:
    . sysuse auto, clear
    (1978 Automobile Data)
    
    . catplot rep78
    
    . catplot rep78, recast(bar)
    Extracts from the help:

    By default catplot is a wrapper for graph hbar. Optionally catplot may be recast as a wrapper for graph bar or graph dot. The choice is a matter of personal taste, although in general horizontal displays make it easier to identify names or labels of categories.

    recast() recasts the graph to another plottype, one of hbar, bar, dot. Note for experienced users: although the name is suggested by another recast() option, this is not a back door to recasting to a twoway plot.

    Comment


    • #3
      Hi Nick,
      sorry for the mislabeling! I meant catplot (I used coefplot for a different part). I will try to edit the title and content, but I did not see a way to do it.
      I tried both -recast(bar)- and -vertical-, but as you predicted the result was not pretty. Are there other options?

      Edit: I added in xsize(10) to keep all the bars from getting squished, but the county names are now overlapping. Is there a way to change the orientation of the county names (bar labels)? I tried making the labels smaller, as suggested in the thread here, but then the county names become illegible.

      Code:
      catplot name, var1opts(sort(1)) vertical xsize(10) ytitle("Number of Wildfires")
      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input str15 name
      "San Diego"      
      "Tehama"        
      "Riverside"      
      "San Luis Obispo"
      "Contra Costa"  
      "Los Angeles"    
      "Modoc"          
      "San Diego"      
      "Siskiyou"      
      "Stanislaus"    
      "Tuolumne"      
      "San Diego"      
      "Del Norte"      
      "Placer"        
      "Fresno"        
      "Madera"        
      "Siskiyou"      
      "Stanislaus"    
      "Calaveras"      
      "Los Angeles"    
      "Monterey"      
      "Mariposa"      
      "El Dorado"      
      "Santa Clara"    
      "Kern"          
      "Mendocino"      
      "Tuolumne"      
      "Fresno"        
      "Tehama"        
      "Trinity"        
      "Lake"          
      "Fresno"        
      "Santa Clara"    
      "Monterey"      
      "San Diego"      
      "Riverside"      
      "Yuba"          
      "Calaveras"      
      "Plumas"        
      "Siskiyou"      
      "Sacramento"    
      "San Joaquin"    
      "Calaveras"      
      "Placer"        
      "Inyo"          
      "Amador"        
      "Riverside"      
      "San Bernardino"
      "Mariposa"      
      "Monterey"      
      "Lake"          
      "Kern"          
      "Monterey"      
      "San Luis Obispo"
      "Inyo"          
      "Los Angeles"    
      "San Joaquin"    
      "Sonoma"        
      "San Diego"      
      "Riverside"      
      "San Joaquin"    
      "Santa Barbara"  
      "Kern"          
      "Tulare"        
      "Tulare"        
      "Fresno"        
      "Butte"          
      "Tuolumne"      
      "Los Angeles"    
      "Los Angeles"    
      "San Bernardino"
      "Siskiyou"      
      "Santa Clara"    
      "San Diego"      
      "Yuba"          
      "Riverside"      
      "Sutter"        
      "Tuolumne"      
      "Inyo"          
      "Yuba"          
      "Contra Costa"  
      "Nevada"        
      "Colusa"        
      "Napa"          
      "Los Angeles"    
      "Shasta"        
      "Los Angeles"    
      "Riverside"      
      "Lassen"        
      "Fresno"        
      "Mariposa"      
      "Imperial"      
      "San Luis Obispo"
      "Lake"          
      "Mendocino"      
      "Tuolumne"      
      "Riverside"      
      "Ventura"        
      "Amador"        
      "Tuolumne"      
      end
      Last edited by Martha Fiehn; 08 May 2019, 15:32.

      Comment


      • #4
        I have one trick that may help. With those example data

        Code:
        contract name
        sort _freq
        gen which = _n < _N/2
        
        catplot name [fw=_freq], var1opts(sort(1) descending) by(which, note("")) nofill ///
        bar(1, blcolor(red) bfcolor(red*0.2))  subtitle("", pos(9) nobox nobexpand)
        Click image for larger version

Name:	ca_fires.png
Views:	1
Size:	34.1 KB
ID:	1497457



        Some counties aren't represented in your example data, but the result with all will still be much less crowded. Breaking the plot in two may be a sacrifice you feel you can make to get a readable display. The game of How did my county fare? is also easier to play.

        PS I use scheme s1color

        Comment


        • #5
          Thank you so much! The code worked perfectly with the whole dataset and scheme(s1color) is exactly what I wanted.

          Comment

          Working...
          X