Announcement

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

  • catplot: combined graph, 12 categorial variables over 1 categorial variable

    Dear Statalist,

    I could use some help with a graph I am trying to produce.
    This is my data:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(region subg user) long(broad issuepol issuecpgn im mob hyb) float iact long(people priv) float(narrative other_fct)
    4 5 2 2 2 2 2 2 2 2 2 2 2 2
    1 2 2 1 1 2 2 1 2 2 1 2 2 2
    1 4 2 2 2 2 2 2 2 2 2 2 2 2
    4 1 2 1 1 2 2 2 2 2 2 2 2 2
    1 2 2 2 2 2 2 2 2 1 2 2 2 2
    2 1 2 1 1 1 2 1 2 2 2 2 2 2
    1 2 2 1 2 2 1 1 1 2 1 1 2 2
    2 1 2 2 1 2 2 2 2 2 2 2 2 2
    7 1 2 1 1 2 1 2 2 2 2 2 2 2
    2 1 2 1 2 2 1 1 2 2 2 1 2 2
    1 1 2 1 1 2 2 2 1 1 1 1 2 2
    1 1 2 1 1 1 1 1 1 2 2 1 2 2
    1 1 2 2 2 2 1 2 2 2 1 1 2 2
    2 1 1 2 2 2 2 2 2 2 1 1 2 2
    7 1 2 1 1 2 1 2 2 2 2 1 2 2
    3 1 2 2 2 2 1 2 2 2 2 2 2 2
    2 1 2 1 1 2 1 2 2 2 2 1 2 2
    2 3 2 1 2 2 2 2 2 1 2 2 2 2
    4 1 2 2 2 2 2 1 2 2 1 2 2 2
    1 4 3 2 2 2 2 2 2 2 2 2 2 2
    4 3 1 2 2 2 2 2 2 2 2 2 2 2
    4 1 2 2 2 2 2 2 2 2 2 1 2 2
    2 1 2 2 2 2 2 2 2 2 2 2 1 2
    4 1 2 2 2 1 1 2 2 2 2 1 2 2
    1 1 2 1 1 2 2 2 2 2 2 2 2 2
    1 1 2 2 2 2 1 2 2 2 1 1 2 2
    4 1 2 1 2 1 2 2 2 2 2 1 2 2
    4 1 2 2 2 2 2 2 2 2 2 2 2 1
    end
    label values region region
    label def region 1 "Europe", modify
    label def region 2 "North America", modify
    label def region 3 "Middle East", modify
    label def region 4 "South East Asia", modify
    label def region 7 "North Caucasus", modify
    label values subg subg
    label def subg 1 "politician", modify
    label def subg 2 "party", modify
    label def subg 3 "government ministry/project", modify
    label def subg 4 "various", modify
    label def subg 5 "not applicable", modify
    label values user trio
    label values broad trio
    label values issuepol trio
    label values issuecpgn trio
    label values im trio
    label values mob trio
    label values hyb trio
    label values iact trio
    label values people trio
    label values priv trio
    label values narrative trio
    label values other_fct trio
    label def trio 1 "a.s.", modify
    label def trio 2 "n.a.", modify
    label def trio 3 "a.w.o.", modify
    Stata Version 14.2 for Windows, package: catplot (SSC)

    I tried this:
    Code:
    set scheme s2mono
    *user*
    catplot user, over(subg) stack percent blabel(bar,pos(base) format(%4.0f)size(3)) bar(2,bfcolor(none)) bar(1,bfcolor(gs10)) bar(3,bfcolor(gs15)) asyvars name(u1, replace) title("User analysis", size(small))
    
    *broad*
    catplot broad, over(subg) stack percent blabel(bar,pos(base) format(%4.0f)size(3)) bar(2,bfcolor(none)) bar(1,bfcolor(gs10)) asyvars name(b1, replace) title("Broadcasting", size(small))
    
    *issuepol*
    catplot issuepol, over(subg) stack percent blabel(bar,pos(base) format(%4.0f)size(3)) bar(2,bfcolor(none)) bar(1,bfcolor(gs10)) asyvars name(ip1, replace) title("Broadcasting: communication of policy issues ", size(small))
    
    *iisuecpgn*
    catplot issuecpgn, over(subg) stack percent blabel(bar,pos(base) format(%4.0f)size(3)) bar(2,bfcolor(none)) bar(1,bfcolor(gs10)) asyvars name(ic1, replace) title("Broadcasting: communication of campaign issues ", size(small))
    
    
    *im*
    catplot im, over(subg) stack percent blabel(bar,pos(base) format(%4.0f)size(3)) bar(2,bfcolor(none)) bar(1,bfcolor(gs10)) asyvars name(im1, replace) title("Image management", size(small))
    
    *mob*
    catplot mob, over(subg) stack percent blabel(bar,pos(base) format(%4.0f)size(3)) bar(2,bfcolor(none)) bar(1,bfcolor(gs10)) asyvars name(m1, replace) title("Mobilization", size(small))
    
    *hyb*
    catplot hyb, over(subg) stack percent blabel(bar,pos(base) format(%4.0f)size(3)) bar(2,bfcolor(none)) bar(1,bfcolor(gs10)) asyvars name(h1, replace) title("Hybridity", size(small))
    
    *iact*
    catplot iact, over(subg) stack percent blabel(bar,pos(base) format(%4.0f)size(3)) bar(2,bfcolor(none)) bar(1,bfcolor(gs10)) asyvars name(ia1, replace) title("Interaction", size(small))
    
    *priv*
    catplot priv, over(subg) stack percent blabel(bar,pos(base) format(%4.0f)size(3)) bar(2,bfcolor(none)) bar(1,bfcolor(gs10)) asyvars name(pv1, replace) title("Personalization: private content", size(small))
    
    *people*
    catplot people, over(subg) stack percent blabel(bar,pos(base) format(%4.0f)size(3)) bar(2,bfcolor(none)) bar(1,bfcolor(gs10)) asyvars name(pl1, replace) title("Personalization: focus on people", size(small))
    
    *narrative*
    catplot narrative, over(subg) stack percent blabel(bar,pos(base) format(%4.0f)size(3)) bar(2,bfcolor(none)) bar(1,bfcolor(gs10)) asyvars name(n1, replace) title("Narrative", size(small))
    
    *other/linguistic*
    catplot other_fct, over(subg) stack percent blabel(bar,pos(base) format(%4.0f)size(3)) bar(2,bfcolor(none)) bar(1,bfcolor(gs10)) asyvars name(sa1, replace) title("Scentence analysis", size(small))
    
    grc1leg u1 b1 ip1 ic1 im1 m1 h1 ia1 pv1 pl1 n1 sa1, ycommon cols(3) title("Function analysed by type of actor (grouped, in percent", size(small))
    to come up with this:



    I would remove 'percent' and the title on the yaxis in the editor and change the size of the legend (I am new to graphs so it's easier for me to do it there).
    But nevertheless, it is quite hard to read and almost impossible to see that the variable "user" is the only one where all three categories come up.

    Maybe someone has an idea for a better solution?

    Best,
    Nadine


  • #2
    Here is one way where the labels are only on the graphs on the left:

    Code:
    set scheme s2mono
    *user*
    catplot user, over(subg ) stack percent blabel(bar,pos(base) /// 
     format(%4.0f)size(3)) bar(2,bfcolor(none)) bar(1,bfcolor(gs10)) /// 
     bar(3,bfcolor(gs15)) asyvars name(u1, replace) /// 
     title("User analysis", size(small)) l1title("")  ytitle("")  /// 
     legend(row(1)) fxsize(125)
    
    
    *broad*
    catplot broad, over(subg , label(nolabels)) stack percent blabel(bar,pos(base) ///
     format(%4.0f)size(3)) bar(2,bfcolor(none)) bar(1,bfcolor(gs10))  asyvars /// 
     name(b1, replace) title("Broadcasting", size(small)) l1title("") ytitle("") ///
     fxsize(100)
     
    *issuepol*
    catplot issuepol, over(subg , label(nolabels)) stack percent blabel(bar,pos(base) /// 
     format(%4.0f)size(3)) bar(2,bfcolor(none)) bar(1,bfcolor(gs10)) asyvars  /// 
     name(ip1, replace) title("Broadcasting: communication of policy issues ", size(small)) /// 
     l1title("")  ytitle("") fxsize(100)
    
    *iisuecpgn*
    catplot issuecpgn, over(subg ) stack percent blabel(bar,pos(base) /// 
     format(%4.0f)size(3)) bar(2,bfcolor(none)) bar(1,bfcolor(gs10)) asyvars /// 
     name(ic1, replace) title("Broadcasting: communication of campaign issues ", size(small)) ///
     l1title("")  ytitle("") fxsize(125)
    
    
    *im*
    catplot im, over(subg, label(nolabels)) stack percent blabel(bar,pos(base) /// 
     format(%4.0f)size(3)) bar(2,bfcolor(none)) bar(1,bfcolor(gs10)) asyvars /// 
     name(im1, replace) title("Image management", size(small)) l1title("")  /// 
     ytitle("") fxsize(100)
    
    *mob*
    catplot mob, over(subg, label(nolabels)) stack percent blabel(bar,pos(base) /// 
     format(%4.0f)size(3)) bar(2,bfcolor(none)) bar(1,bfcolor(gs10)) asyvars /// 
     name(m1, replace) title("Mobilization", size(small)) l1title("") /// 
     ytitle("") fxsize(100)
    
    *hyb*
    catplot hyb, over(subg ) stack percent blabel(bar,pos(base) /// 
     format(%4.0f)size(3)) bar(2,bfcolor(none)) bar(1,bfcolor(gs10)) asyvars  /// 
     name(h1, replace) title("Hybridity", size(small))  l1title("")  ytitle("") /// 
     fxsize(125)
    
    *iact*
    catplot iact, over(subg, label(nolabels)) stack percent blabel(bar,pos(base) /// 
     format(%4.0f)size(3)) bar(2,bfcolor(none)) bar(1,bfcolor(gs10)) asyvars /// 
     name(ia1, replace) title("Interaction", size(small)) l1title("") ytitle("") /// 
     fxsize(100)
    
    *priv*
    catplot priv, over(subg, label(nolabels)) stack percent blabel(bar,pos(base) /// 
    format(%4.0f)size(3)) bar(2,bfcolor(none)) bar(1,bfcolor(gs10)) asyvars /// 
     name(pv1, replace) title("Personalization: private content", size(small)) /// 
     l1title("")  ytitle("") fxsize(100)
    
    *people*
    catplot people, over(subg ) stack percent blabel(bar,pos(base) /// 
     format(%4.0f)size(3)) bar(2,bfcolor(none)) bar(1,bfcolor(gs10)) asyvars /// 
     name(pl1, replace) title("Personalization: focus on people", size(small)) ///
     l1title("")  ytitle("") fxsize(125) 
    
    *narrative*
    catplot narrative, over(subg, label(nolabels)) stack percent blabel(bar,pos(base) /// 
     format(%4.0f)size(3 )) bar(2,bfcolor(none)) bar(1,bfcolor(gs10)) asyvars  /// 
     name(n1, replace) title("Narrative", size(small)) l1title("") ytitle("") fxsize(100)
    
    *other/linguistic*
    catplot other_fct, over(subg, label(nolabels)) stack percent blabel(bar,pos(base) /// 
     format(%4.0f)size(3)) bar(2,bfcolor(none)) bar(1,bfcolor(gs10)) asyvars /// 
     name(sa1, replace) title("Scentence analysis", size(small)) l1title("") ///
     ytitle("") fxsize(100)
    
    
    grc1leg  u1 b1 ip1 ic1 im1 m1 h1 ia1 pv1 pl1 n1 sa1,  cols(3) /// 
     title("Function analysed by type of actor (grouped, in percent)", size(small)) /// 
     legendfrom(u1)
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	57.3 KB
ID:	1539859

    Comment


    • #3
      I can't read the graph in #1. So here it is:

      Click image for larger version

Name:	NB.png
Views:	1
Size:	54.6 KB
ID:	1539879


      catplot is here just a wrapper for graph hbar.

      I don't like stacking much, so here is an alternative to Scott's interesting design. The similarities are perhaps a bigger deal than the differences.

      I use tabplot from the Stata Journal.

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input float(region subg user) long(broad issuepol issuecpgn im mob hyb) float iact long(people priv) float(narrative other_fct)
      4 5 2 2 2 2 2 2 2 2 2 2 2 2
      1 2 2 1 1 2 2 1 2 2 1 2 2 2
      1 4 2 2 2 2 2 2 2 2 2 2 2 2
      4 1 2 1 1 2 2 2 2 2 2 2 2 2
      1 2 2 2 2 2 2 2 2 1 2 2 2 2
      2 1 2 1 1 1 2 1 2 2 2 2 2 2
      1 2 2 1 2 2 1 1 1 2 1 1 2 2
      2 1 2 2 1 2 2 2 2 2 2 2 2 2
      7 1 2 1 1 2 1 2 2 2 2 2 2 2
      2 1 2 1 2 2 1 1 2 2 2 1 2 2
      1 1 2 1 1 2 2 2 1 1 1 1 2 2
      1 1 2 1 1 1 1 1 1 2 2 1 2 2
      1 1 2 2 2 2 1 2 2 2 1 1 2 2
      2 1 1 2 2 2 2 2 2 2 1 1 2 2
      7 1 2 1 1 2 1 2 2 2 2 1 2 2
      3 1 2 2 2 2 1 2 2 2 2 2 2 2
      2 1 2 1 1 2 1 2 2 2 2 1 2 2
      2 3 2 1 2 2 2 2 2 1 2 2 2 2
      4 1 2 2 2 2 2 1 2 2 1 2 2 2
      1 4 3 2 2 2 2 2 2 2 2 2 2 2
      4 3 1 2 2 2 2 2 2 2 2 2 2 2
      4 1 2 2 2 2 2 2 2 2 2 1 2 2
      2 1 2 2 2 2 2 2 2 2 2 2 1 2
      4 1 2 2 2 1 1 2 2 2 2 1 2 2
      1 1 2 1 1 2 2 2 2 2 2 2 2 2
      1 1 2 2 2 2 1 2 2 2 1 1 2 2
      4 1 2 1 2 1 2 2 2 2 2 1 2 2
      4 1 2 2 2 2 2 2 2 2 2 2 2 1
      end
      label values region region
      label def region 1 "Europe", modify
      label def region 2 "North America", modify
      label def region 3 "Middle East", modify
      label def region 4 "South East Asia", modify
      label def region 7 "North Caucasus", modify
      label values subg subg
      label def subg 1 "politician", modify
      label def subg 2 "party", modify
      label def subg 3 "government ministry/project", modify
      label def subg 4 "various", modify
      label def subg 5 "not applicable", modify
      label values user trio
      label values broad trio
      label values issuepol trio
      label values issuecpgn trio
      label values im trio
      label values mob trio
      label values hyb trio
      label values iact trio
      label values people trio
      label values priv trio
      label values narrative trio
      label values other_fct trio
      label def trio 1 "a.s.", modify
      label def trio 2 "n.a.", modify
      label def trio 3 "a.w.o.", modify
      
      rename (user broad issuepol issuecpgn im mob hyb iact people priv narrative other_fct) (reaction#), addnumber 
      gen id = _n 
      reshape long reaction, i(id) j(which) 
      
      label def which 1  "User analysis" ///
      2 "Broadcasting" 3 "Policy issues" ///
      4 "Campaign issues" 5 "Image management" ///
      6 "Mobilization" 7 "Hybridity" 8 "Interaction" ///
      9 "Focus on people" 10 "Private content" 11 "Narrative" 12 "Sentence analysis" 
      
      label val which which 
      
      tabplot subg reaction, by(which, note("")) percent(which) horizontal ///
      showval(offset(0.3) format(%1.0f)) xtitle("") ytitle("") fcolor(none) xsc(r(0.9 .)) ///
      subtitle(, fcolor(ltblue)) scheme(s1color)
      Click image for larger version

Name:	NJC.png
Views:	2
Size:	38.5 KB
ID:	1539881
      Attached Files

      Comment


      • #4
        These are both great solutions. Especially the second one is very easy to read, just what I was looking for. Thank you both very much, this is much appreciated!

        Comment

        Working...
        X