Announcement

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

  • Catplot - Varying Base & Intensity Colors Across Multiple Groups

    Hello,

    I am using catplot (thanks Nick for the great package) and I am trying to have 2 dimensions of colors. In the first variable grouping, I want different intensities of color by group. In the second variable grouping, I want different base colors e.g. blue, red, and purple. For example, see the below code:

    For some data input use below:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte(politics political_degree)
    1 2
    2 3
    2 3
    2 3
    2 3
    2 2
    2 2
    2 2
    2 2
    1 5
    1 5
    1 5
    1 5
    1 3
    1 3
    1 3
    1 3
    0 4
    0 4
    0 4
    0 4
    end
    For the graph template that I am currently working with see below:

    Code:
    catplot political_degree politics, ///
          percent(politics) ///
          var1opts(relabel(1 "Not at all" 2 " " ///
          3 " " 4 " " 5 "Exetremely") label(labsize(small))) ///
          var2opts(relabel(1 "Independent/Other" 2 "Republican Party" 3 "Democratic Party") label(labsize(small))) ///
          l1title("") ///
          ytitle("Percent of Participants by Political Party", size(small)) ///
          title("Political Party Affiliation by Strength of Association", size(medium)) ///
          recast(bar) ///
          blabel(bar, format(%4.1f) size(vsmall)) ///
          graphregion(fcolor(white)) ///
          intensity(25) ///
          asyvars ///
          bar(1, color(navy) fintensity(inten20)) ///
          bar(2, color(navy) fintensity(inten40)) ///
          bar(3, color(navy) fintensity(inten60)) ///
          bar(4, color(navy) fintensity(inten80)) ///
          bar(5, color(navy) fintensity(inten100)) ///
          legend(rows(1) stack size(small) ///
          order(1 "Not at all" 2 "" 3 "" ///
          4 "" 5 "Extremely") ///
          symplacement(center) ///
          title(Strength of Political Affiliation, size(small)))
    In essence, what I am trying to figure out is how I can keep the scaling intensity of the colors regarding political degree, but vary the base color between the politics variable e.g. political party. Also, if at all possible, I want to then retain the color in the legend a gray base with then scaling intensity as well.

    Is this at all possible? Does it have something to do with putting bar() inside of var#opt?

    Any help would be great!

    Best

    Nick

  • #2
    Thanks for the thanks, but I can have it both ways by underlining that catplot (SSC) is here just a wrapper for graph bar and as such doesn't have any special hooks for bar colours.

    You want 15 different colours and for that I think you need to separate your party variable into 3 different variables.

    You could give all the data relevant to the plot with

    Code:
    contract politics political_degree
    dataex
    Both my children, but they aren't offended or hurt by partiality: I think tabplot (SSC) will work better here.

    Comment


    • #3
      Nick,

      Ahh yes, I was just playing around with tabplot and I agree it will probably better serve my purpose. Let me see what I can make of it and get back a little later.

      While it is ultimately more important to learn to code it, if I feel like I am getting nowhere I can always use the graph editor.

      Thanks, Nick!

      Best,

      Fellow Nick



      Comment

      Working...
      X