Announcement

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

  • how to combine (as in overlap) multiple catplots?

    Hi Guys,

    Hope you're all well.

    Code:
    catplot letter if 2020dummy==1, percent hor var1opts(sort(1) descending)
    catplot letter if 2019dummy==1, percent hor var1opts(sort(1) descending)

    I have these two separate catplots, and am trying to figure a way out to put them on one graph, on top of one another, with different colour bars. The categories are exactly the same for the variable 'letter'.

    Any help is appreciated!


  • #2
    Create a new binary variable (let's say it's call year19_20) that is 1 if year = 2019 and 2 if year = 2020. Then:

    Code:
    catplot letter year19_20

    Comment


    • #3
      Hi Ken, thanks for your help.

      This seems to literally put the two separate graphs next to each other in one graph.

      I was looking for a solution where it is just one graph with overlapping bars where one set is one colour and another is another colour.



      Like this

      Comment


      • #4
        Then I am not sure how to do that in catplot. I would perhaps go back to bar plot:

        Code:
        sysuse auto, clear
        drop if rep78 == .
        gen fre = 1
        
        collapse (count) fre, by(rep78 foreign)
        
        gen id = _n
        reshape wide fre, i(id) j(foreign)
        graph bar fre0 fre1, over(rep78) stack

        Comment


        • #5
          catplot is from SSC, as you are asked to explain (FAQ Advice #12).

          Here is some more technique following the spirit of @Ken Chui's idea.

          Code:
          sysuse auto, clear
          
          set scheme s1color 
          
          twoway histogram rep78, freq discrete lcolor(blue) fcolor(none) barw(0.8) || histogram rep78 if foreign, lcolor(red) fcolor(red) freq discrete color(red*0.5) barw(0.8) legend(order(1 "All" 2 "Foreign") pos(11) col(1) ring(0))
          Click image for larger version

Name:	twocolourhist.png
Views:	1
Size:	20.3 KB
ID:	1674749

          Comment


          • #6
            Thank you gentlemen

            Comment

            Working...
            X