Announcement

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

  • spmap - sequential and categorical colors

    Dear all,

    I need some help with using spmap (am new to using GIS with Stata). I have a polygon map where I have an attribute that I could like to display using sequential colors. This works based well:

    spmap att1 using "$path/Maps/coorddta", ///
    id(mapid) fcolor(Blues) ///
    title("Title") ///
    legend(stack rows(1)) ndfcolor(black) ndo(black) ///
    clmethod(custom) clbreaks(0 1 4 14 24)

    Some of the polygons on the map are forests (which I could like to display in green) and some others are mountains (which I could like to display in brown). I am not sure how to combine the sequential Blues with the categorical green and brown. I tried using two different attribute variables but it looks like spmap only accepts one attribute. I coded the polygons with forests and mountains as 98 and 99 for the att1 variable but the colors used are based on the Blues sequential shade.

    I will appreciate any help. Thanks!

  • #2
    Hello Jack,

    Welcome to the Stata Forum.

    It would be much more informative if you presented the graphs. Please, try to present the commands under CODE delimiters as well, as recommended in the FAQ.

    Also, I just wish to remind that, still according to the instructions from the FAQ, user-written programs - as spmap - shall be specified in the first query.

    Among the reasons for that, people who are not well acquainted to a specific SSC may (confusingly) take the commands in #1 as directly available in Stata's regular version.

    Another reason is (dutifully) giving praise to the creators of the program. For example, Maurizio Pisati (from Milan) is the author of this program.

    Now, if I understood correctly in spite of the scarce information presented, and considering my feeble expertise on - spmap - up to now, I strongly recommend you take at look at the option "fcolor".

    Instead of "Blues". I gather you may select exactly the sequence of colors you wish for your graph, for example, "fcolor (green maroon red)".

    Hopefully that helps!

    Best,

    Marcos
    Best regards,

    Marcos

    Comment


    • #3
      Hello Marcos,

      Thanks for your response and my apologies for not following the FAQ.

      So to clarify, spmap is a user written program (thanks Maurizio Pisati!) that allows users to work with GIS shapefiles via Stata. This program is incredibly useful especially if you want to integrate maps into the Stata code and/or if you do not wish to shell out extra $ for an ArcGIS license. To install this program, the code is

      Code:
      ssc install spmap
      ssc install shp2dta
      The code that I am using is
      Code:
       
      spmap att1 using "$path/Maps/coord.dta", ///
      id(mapid) fcolor(Blues) ///
      title("Title") ///
      legend(stack rows(1)) ndfcolor(black) ndo(black) ///
      clmethod(custom) clbreaks(0 1 4 14 24)
      Thanks also for your suggested solution on the use of the fcolor() option - I have tried this but have not been able to get different shades of blue for the different levels of the att1 attribute variable.

      ArcGIS has an option for users to select colors based on a specific value as well as include a sequential color range for other values. If such an option is available in spmap, that would be most useful.

      Thanks again for your help.

      Comment


      • #4
        Jack Simha I don't suspect you'll have a ton of luck with this as the color palettes you referenced are fixed with regards to the individual colors. That said, if you need more flexibility for the cartographic aspects of things, I would highly recommend checking out QGIS. I has a nearly identical feature set to what ArcGIS offers and costs a total of $0. I'm not sure how all of the polygons are drawn, but if you wanted to implement some of the graphing manually, you could do something like this with brewscheme, but first creating a new color palette and then using it to generate a new scheme file. Unfortunately, I don't believe spmap allows users to pass a scheme option to the underlying graph commands.

        Comment


        • #5
          Dear Jack,

          here is an example of a possible way to go, based on the datasets distributed with spmap.

          The main trick is to have two separate map files:
          (a) one containing the coordinates of the polygons representing the study areas of interest, i.e., those to be filled with "Blues";
          (b) the other containing the coordinates of the polygons representing the extra geographical features of interest, e.g., forests and mountains.

          Since in the datasets distributed with spmap there is no map file of the second kind, first I create one pretending that Italian regions 2 and 17 are "forests", while region 14 is "mountains"; the remaining seventeen Italian regions are treated as the study areas of interest, to be filled with different shades of blue according to the value of variable relig1 (Pct. catholics without reservations).

          Here is the code:

          Code:
          * Create dummy map file "geocoord.dta"
          use "Italy-RegionsCoordinates.dta", clear
          keep if inlist(_ID,2,14,17)
          generate geo = .
          replace geo = 1 if inlist(_ID,2,17)
          replace geo = 2 if inlist(_ID,14)
          label define geo 1 "Forests" 2 "Mountains"
          label values geo geo
          save "geocoord.dta", replace
          
          * Draw map
          use "Italy-RegionsData.dta", clear
          spmap relig1 using "Italy-RegionsCoordinates.dta", id(id) fcolor(Blues) polygon(data("geocoord.dta") by(geo) fcolor(green brown) legenda(on))
          For all the bells and whistles, please refer to the spmap help file.
          Best wishes,
          Maurizio

          Comment


          • #6
            Maurizio Pisati out of curiosity, is there any particular reason why -spmap- doesn't allow a scheme option?

            Comment


            • #7
              Dear wbuchanan, thank you for the suggestion to use QGIS. I had looked at it many months ago. But for various reasons, I would like to use Stata (if possible) since it has a number of useful features and integrates better with the rest of the project code.

              Dear Maurizo Pisati, thank you for the sample code. I will definitely try it out and report back. From what I can see, the coordinates database has 3 variables (_ID, X and Y) and I was not sure how to identify which one refers to forests/mountains etc. I have not used the inlist() feature before and I will try it out. And it's always great to hear back from the author of the user-written program!

              Comment


              • #8
                Dear Maurizo Pisati, a quick follow-up question. In the shape file, I see a FID folder that starts from 0 till N. And when using shp2dta, I see that the coordinates database has an _ID variable that goes from 1 to N+1. Is it correct to assume that there _ID = FID + 1? This will help me determine which _IDs refer to forests/mountains etc.

                Thanks again for your help.

                Comment


                • #9
                  Sorry, I mean FID field in the shape file.

                  Comment


                  • #10
                    Dear William,
                    when I wrote spmap, I thought that the 40+ color schemes allowed by option fcolor() were enough for most users, so I didn't think of adding a scheme option. Anyway, users can always specify their own scheme entering any colorstyle list of choice, if desired.

                    Dear Jack,
                    since I have no idea of how your shapefiles are organized, I cannot be of help here, although your intuition does make sense.

                    Best wishes,
                    Maurizio

                    Comment


                    • #11
                      Maurizio Pisati I understand that you have a significant number of options available, it was just a question of curiosity - and because I've spent a non-trivial amount of time/effort working on a program that I think might be complementary that makes it easier for users to generate customized scheme files.

                      Comment

                      Working...
                      X