Announcement

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

  • -geoplot- question about Ben Jann's new command: How can I have the exact number displayed under the name of each regions?

    Hi everyone,

    I have a very quick question about Ben Jann's excellent new command: -geoplot-, and I have been struggling with it for a while.

    It is probably very simple, but here is my question:
    • How could I obtain the exact number of observations just below the name regions, please?
    Here is the code that I used:

    Code:
    *******
    cd ${path_geoloc}/data 
    
    
    spshape2dta "../recintos_autonomicas_inspire_peninbal_etrs89/recintos_autonomicas_inspire_peninbal_etrs89.shp", replace saving(Spain_auton)
    spshape2dta "../recintos_provinciales_inspire_peninbal_etrs89/recintos_provinciales_inspire_peninbal_etrs89.shp", replace saving(Spain_provinc)
    
    
    use Spain_provinc, clear
    gen sp_zipcode_twodigits = substr(NATCODE,5, 2)
    destring sp_zipcode_twodigits, replace
    sort sp_zipcode_twodigits
    save Spain_provinc.dta, replace
    
    
    *1)Creation of Provincias limits
    geoframe create Spain_provinc, replace
    geoframe describe Spain_provinc    
    
    
    
    *3)Some data cleaning, if needed
    geoframe describe Spain_provinc_shp
    merge 1:1 sp_zipcode_twodigits using solar_panel_info_collapse.dta, keep(match master) nogenerate
    drop in -1/l // erase "Territorio..."
    save Spain_provinc, replace
    
    cd ${path_geoloc}/data
    *4)Creation of CCAA limits
    geoframe create Spain_auton
    geoframe describe Spain_auton_shp
    
    *5)Creation of solar_panel_info_collapse connexion
    geoframe create solar_panel_info_collapse, replace
    geoframe describe solar_panel_info_collapse
    
    
    geoplot ///
        (area Spain_provinc obs_by_zipcode_solar, color(sfso orange, reverse) cuts(0 50 100 200 300 400 500 1500 2500 4500)) ///
        (line Spain_auton, lwidth(0.4)) ///
        (line Spain_provinc, lwidth(0.05)) ///
        (label Spain_provinc NAMEUNIT, size(tiny) color(black)), tight legend(pos(9))
    
    
    cd ${EEL_ERG_02112023}/figures 
    
    graph export map_obs_by_zipcodes_solarp_geoplot.png, replace
    graph export map_obs_by_zipcodes_solarp_geoplot.pdf, replace
    The map is depicted below.
    All the best,

    Michael

    Click image for larger version

Name:	map_obs_by_zipcodes_solarp_geoplot.png
Views:	1
Size:	203.0 KB
ID:	1732131

  • #2
    Dear Michael,

    Reading the reply of Ben Jann on a similar request on his Github page of geoplot, to get the labels that you need, I conclude that you will have to do this with additional coding.
    As he recommends, you should take a look at this Statalist post that discusses among other aspects what you are looking for, in particular the post of Robert Picard at #6.

    Furthermore, you should take care that you have installed the last version of geoplot, that also utilizes the current Stata 18 update ( "04 Oct 2023") functionality of the internal command aspectratio(1, units) which creates a graph where one unit in the x dimension and one unit in the y dimension each take up the same distance on the plot.
    Code:
     
     net install geoplot, replace from(https://raw.githubusercontent.com/benjann/geoplot/main/)
    This is useful for plotting things such as latitude against longitude, which have common scaling of their units.
    That will prevent the distortion of the geographical proportion of the Iberian Peninsula in your data visualization at #1.
    http://publicationslist.org/eric.melse

    Comment


    • #3
      Hi ericmelse,

      Thank you for your post in #2!
      • I have still the old stata17. The new version of geoplot could work even if I haven't the new version of stata installed?
      The post of Robert Picard is awesome. Thank you.

      Best,

      Michael

      Comment


      • #4
        Yes, geoplot will run using Stata 17, actually, Stata version 16.1 or newer is required, but you can use the option aspectratio only when you run using Stata 18.
        http://publicationslist.org/eric.melse

        Comment


        • #5
          Hi Eric,

          Ok, so I cannot be able to use aspectratio unfortunately.
          Thanks all the same for your advices!

          All the best,

          Michael

          Comment


          • #6
            The comment by Eric about aspectratio() is misleading. geoplot makes sure that the aspect ratio is set in terms of units of x and y in all supported versions of Stata. Internally, this is achieved using a somewhat different approach since Stata 18 update 04 Oct 2023, but this doesn't matter for users. Syntax and behavior is the same in all Stata versions. ben

            Comment


            • #7
              With respect to the original question: Simply add the numbers using an additional label layer. About as folliows:

              Code:
              geoplot ///
                  (area Spain_provinc obs_by_zipcode_solar, color(sfso orange, reverse) cuts(0 50 100 200 300 400 500 1500 2500 4500)) ///
                  (line Spain_auton, lwidth(0.4)) ///
                  (line Spain_provinc, lwidth(0.05)) ///
                  (label Spain_provinc NAMEUNIT, size(tiny) color(black)) ///
                  (label Spain_provinc obs_by_zipcode_solar, size(tiny) color(black) position(6)) ///
                  , tight legend(pos(9))

              Comment


              • #8
                Hi Ben Jann:

                Thank you very much for your suggestion.
                Works perfectly.

                Best,
                Michael

                Comment

                Working...
                X