# How to objectively subset cities by population

6 messages
Open this post in threaded view
|

## How to objectively subset cities by population

 Dear all, I have temperature records of nearly 1200 locations in southern Brazil. I am writing a shiny app that will show an interactive map with the locations plotted as circles, where the user can click a location to see its temperature time series. However, if I show all the locations in the map, it will look really bad, too cramped. Therefore, in an attempt to make the map look a bit cleaner, I am trying to think of an objective way to subset the locations. My initial approach would be to show only the "largest" locations, i.e. the ones with a population above a certain threshold. The problem is: the distribution of the population is so positively skewed that I am having a hard time determining the optimal cutoff point. Does anybody here know any tool or method, possibly spatial, that can assist me with this analysis? These are the locations I am working with: #------------------------------- # Download and summarize locs <- read.csv("https://www.dropbox.com/s/ykdd8x1mlc76klt/locations.csv?raw=1") hist(locs\$Population) summary(locs\$Population) # Convert to spatial points and plot require(sp) coordinates(locs) <- cbind(locs\$Lon , locs\$Lat) plot(locs) bubble(locs,"Population") #------------------------------- Thanks in advance,  -- Thiago V. dos Santos PhD student Land and Atmospheric Science University of Minnesota         [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list [hidden email] https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Open this post in threaded view
|

## Re: How to objectively subset cities by population

 Dear Thiago, if you want them spatially evenly distributed, you could overlay a grid and select the largest per grid box - or maybe more intuitive, select the largest per predefined administrative areas (counties/postal codes/...). This could also change based on zoom-level. An alternative is to group sensors and expand and zoom in by clicking on the group (see e.g. [1]). HTH,   Ben [1] http://sensorweb.demo.52north.org/client/#/mapOn 27/07/2017 06:09, Thiago V. dos Santos via R-sig-Geo wrote: > Dear all, > > I have temperature records of nearly 1200 locations in southern Brazil. > > I am writing a shiny app that will show an interactive map with the locations plotted as circles, where the user can click a location to see its temperature time series. > > However, if I show all the locations in the map, it will look really bad, too cramped. > > Therefore, in an attempt to make the map look a bit cleaner, I am trying to think of an objective way to subset the locations. My initial approach would be to show only the "largest" locations, i.e. the ones with a population above a certain threshold. > > The problem is: the distribution of the population is so positively skewed that I am having a hard time determining the optimal cutoff point. > > Does anybody here know any tool or method, possibly spatial, that can assist me with this analysis? > > These are the locations I am working with: > > #------------------------------- > # Download and summarize > locs <- read.csv("https://www.dropbox.com/s/ykdd8x1mlc76klt/locations.csv?raw=1") > hist(locs\$Population) > summary(locs\$Population) > > # Convert to spatial points and plot > require(sp) > coordinates(locs) <- cbind(locs\$Lon , locs\$Lat) > plot(locs) > bubble(locs,"Population") > #------------------------------- > > Thanks in advance, >   -- Thiago V. dos Santos > > PhD student > Land and Atmospheric Science > University of Minnesota > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-Geo mailing list > [hidden email] > https://stat.ethz.ch/mailman/listinfo/r-sig-geo> -- Dr. Benedikt Gräler 52°North Initiative for Geospatial Open Source Software GmbH Martin-Luther-King-Weg 24 48155 Muenster, Germany E-Mail: [hidden email] Fon: +49-(0)-251/396371-39 Fax: +49-(0)-251/396371-11 http://52north.org/Twitter: @FiveTwoN General Managers: Dr. Albert Remke, Dr. Andreas Wytzisk Local Court Muenster HRB 10849 _______________________________________________ R-sig-Geo mailing list [hidden email] https://stat.ethz.ch/mailman/listinfo/r-sig-geo b_graeler.vcf (458 bytes) Download Attachment
Open this post in threaded view
|

## Re: How to objectively subset cities by population

 In reply to this post by R-sig-geo mailing list > > Date: Thu, 27 Jul 2017 04:09:53 +0000 (UTC) > From: "Thiago V. dos Santos" <[hidden email]> > To: R-sig-geo Mailing List <[hidden email]> > Subject: [R-sig-Geo] How to objectively subset cities by population > Message-ID: <[hidden email]> > Content-Type: text/plain; charset="UTF-8" > > Dear all, > > I have temperature records of nearly 1200 locations in southern Brazil. > > I am writing a shiny app that will show an interactive map with the > locations plotted as circles, where the user can click a location to see > its temperature time series. > > However, if I show all the locations in the map, it will look really bad, > too cramped. > Have you considered using leaflet to make an interactive map? This is a good start: library(leaflet) locs <- read.csv(" https://www.dropbox.com/s/ykdd8x1mlc76klt/locations.csv?raw=1") leaflet(locs) %>% addTiles() %>%   addCircles(radius=~20*sqrt(Population), label=~as.character(Geocode),              stroke=FALSE, fillOpacity=0.5) You can configure popups to show HTML or get Shiny events on click, for example clicking on a city could display the time series in a separate panel. Docs and many examples on the leaflet for R web site: https://rstudio.github.io/leaflet/Kent         [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list [hidden email] https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Open this post in threaded view
|

## Re: How to objectively subset cities by population

 Hi Kent, Thank you very much for the response. This is exactly the same approach I am using now, with a different radius formula though. It is not at all terrible, but do you see how overlapped the largest cities are, and how difficult it is to click on some smaller cities? This is why I am looking for an objective way to filter out the smallest cities, while at the same time keeping as much information on the map as possible (i.e. not leaving too many "blank" areas).  Best, -- Thiago V. dos Santos PhD studentLand and Atmospheric ScienceUniversity of Minnesota On Thursday, July 27, 2017, 7:29:44 AM CDT, Kent Johnson <[hidden email]> wrote: Date: Thu, 27 Jul 2017 04:09:53 +0000 (UTC) From: "Thiago V. dos Santos" <[hidden email]> To: R-sig-geo Mailing List <[hidden email]> Subject: [R-sig-Geo] How to objectively subset cities by population Message-ID: <1634627903.292923. [hidden email]> Content-Type: text/plain; charset="UTF-8" Dear all, I have temperature records of nearly 1200 locations in southern Brazil. I am writing a shiny app that will show an interactive map with the locations plotted as circles, where the user can click a location to see its temperature time series. However, if I show all the locations in the map, it will look really bad, too cramped. Have you considered using leaflet to make an interactive map? This is a good start: library(leaflet)locs <- read.csv("https://www.dropbox.com/s/ykdd8x1mlc76klt/locations.csv?raw=1") leaflet(locs) %>% addTiles() %>%   addCircles(radius=~20*sqrt(Population), label=~as.character(Geocode),              stroke=FALSE, fillOpacity=0.5) You can configure popups to show HTML or get Shiny events on click, for example clicking on a city could display the time series in a separate panel. Docs and many examples on the leaflet for R web site: https://rstudio.github.io/leaflet/Kent         [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list [hidden email] https://stat.ethz.ch/mailman/listinfo/r-sig-geo