Announcement

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

  • Reversing the color scale in shape map using spmap

    Dear Statalists,

    I am investigating the effect of a liberalisation of the divorce law on the fertility rates in Danish municipalities (this effect is negative and significant). The data I am using is panel data. To see which municipalities have been affected the most, I have calculated the percentage change in the fertility rate between 2008 and 2018 for each municipality. Now, I want to illustrate this using Stata's command
    Code:
    spmap
    .

    My problem is that the municipalities that are affected the most have the lowest value and thus the lightest shade whereas the municipalities that are affected the least have the highest value and thus the darkest shade. This seems counterintuitive which is why I want to reverse the color scale in the shape map.

    Here is my code:
    Code:
    clear all
    cd /Users/maigoetzsche/Desktop
    ssc install shp2dta
    ssc install spmap
    
    use denmark_dat, clear
    rename NAME_2 municipality
    replace municipality = "Copenhagen" if  municipality =="København"
    replace municipality = "Ærø" if  municipality =="Ærø"
    replace municipality = "Aarhus" if  municipality =="Århus"
    replace municipality = "Høje-Taastrup" if  municipality =="Høje Taastrup"
    replace municipality = "Vesthimmerlands" if  municipality =="Vesthimmerland"
    save  denmark_harm, replace
    
    import excel "Datasheets.xlsx", sheet("Data10") firstrow clear
    drop id            
    save main, replace    
    use denmark_harm, clear
    merge 1:1 municipality using main
     
    spmap divorcechange using denmark_co, plotregion(lcolor(black)) fcolor(OrRd) id(id) osize(vthin vthin vthin vthin) ndsize(vthin)  ///  
    legend(position(2)) legtitle("fertilitychange") clnumber(9) legend(size(medium))
    This gives the following:
    Click image for larger version

Name:	Shape map.png
Views:	1
Size:	167.1 KB
ID:	1579065



    Can anyone help?

    Thank you in advance.

    Best,
    Mai

  • #2
    Hey,

    I have the same question. I just cannot find a way to reverse the shades of blue of my map without digging into more complicated syntax of colorpalette. Can someone give a hint if there is a simple way of solving this?

    Best,
    Julian

    Comment


    • #3
      I'm also trying to solve this one. Any solutions? My current workaround is to multiply my variable by -1 but it's far from ideal for the legend.

      Comment


      • #4
        Eventually I managed to solve it this way:

        First install the following packages:
        Code:
        ssc install palettes, replace    // for color palettes
        ssc install colrspace, replace   // for expanding the color base
        Then generate a local in order to reverse the scheme. In my case this was darkest blue for lowest number:
        Code:
        colorpalette Blues, select(2 4 6 8) nograph reverse // this reverses the colors, here I selected 4 different blues
        local colors `r(p)'

        Then when mapping simply use this local when assinging fcolor:
        Code:
        spmap clashes_tot using coord, id(id) fcolor("`colors'")
        Perhaps there are better ways but I hope this helps you.

        Best,
        Julian

        Comment


        • #5
          Originally posted by Julian Schaper View Post
          Eventually I managed to solve it this way:

          First install the following packages:
          Code:
          ssc install palettes, replace // for color palettes
          ssc install colrspace, replace // for expanding the color base
          Then generate a local in order to reverse the scheme. In my case this was darkest blue for lowest number:
          Code:
          colorpalette Blues, select(2 4 6 8) nograph reverse // this reverses the colors, here I selected 4 different blues
          local colors `r(p)'

          Then when mapping simply use this local when assinging fcolor:
          Code:
          spmap clashes_tot using coord, id(id) fcolor("`colors'")
          Perhaps there are better ways but I hope this helps you.

          Best,
          Julian

          Hi, I tried your command and it works!
          However, the areas that should display the least intense colour are white-filled. I tried to change the color scale within "select", but with no results. Can you help me?

          Best,
          Francesco

          Comment

          Working...
          X