Announcement

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

  • spmap: assign a specific color to the value of a categorical variable

    Hi,

    I am trying to produce a map using a categorical variable with 16 categories. For each category, I want spmap to use a specific color I define using RGB. I am using the code below.

    [CODE][spmap delta_sup_rli_lowlow using world_shp2, id(_ID) clnum(16) clmethod(unique) fcolor( "255 234 216" "255 213 178" "255 171 103" "255 129 5" "218 156 179" "229 137 127" "243 123 91" "252 87 41" "151 67 143" "184 61 115" "222 72 92" "240 35 63" "3 3 127" "99 0 124" "189 0 100" "219 0 83" ) osize(vvthin vvthin vvthin vvthin) ndsize(vvthin)/CODE]


    The values in fcolor() are in order to each of the categories in my categorical variables, from 1 to 16. That is, value 1 takes color "255 234 216", value 2 "255 171 103", and so on.

    However, spmap re-allocates the colors using some other criteria. I made different tries, but I can't find a way, nor documentation, that helps me with this. Does anyone please give me an advice?

    thanks,
    Matías




  • #2
    spmap is from SSC, as you are asked to explain (FAQ Advice #12). You probably have to tinker with the levels of the scale - effectively having an ordinal scale instead of a continuous one. As always, you will do yourself a favor by presenting a reproducible example as recommended in the referenced FAQ Advice.

    Comment


    • #3
      Matias Piaggio , here is an example using your RBG categories that appears to work - that the category numbers match the color list.

      Code:
      use "Italy-RegionsData.dta", clear
      xtile relig_category = relig1, n(16)
      expand 2, gen(expand)
      generate cat = string(relig_cat) if expand == 0
      replace cat =region if expand == 1
      
      spmap relig_category using "Italy-RegionsCoordinates.dta" in 1/20, id(id) /// 
          clnum(16) clmethod(unique)   /// 
           fcolor( "255 234 216" "255 213 178" "255 171 103" "255 129 5" /// 
           "218 156 179" "229 137 127" "243 123 91" "252 87 41" "151 67 143" /// 
           "184 61 115" "222 72 92" "240 35 63" "3 3 127" "99 0 124" /// 
           "189 0 100" "219 0 83" )   /// 
            label(xcoord(xcoord)  ycoord(ycoord) label(cat)  by(expand)  pos(12 0))
      Click image for larger version

Name:	map.png
Views:	1
Size:	98.7 KB
ID:	1721427

      Comment

      Working...
      X