How to objectively subset cities by population

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to objectively subset cities by population

R-sig-geo mailing list
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
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to objectively subset cities by population

Dr. Benedikt Gräler
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/#/map


On 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
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to objectively subset cities by population

Kent Johnson
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
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to objectively subset cities by population

R-sig-geo mailing list
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
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to objectively subset cities by population

R-sig-geo mailing list
In reply to this post by Dr. Benedikt Gräler
Dear Dr. Gräler,
Thanks for your contribution. I very much enjoyed the clustering suggestion, and it seems to be available in R's leaflet through the "markerClusterOptions" command. It could solve my problem, so I will take a closer look at that.
Regarding your first suggestion, can you point me out some example that uses the overlaid grid approach?
Thanks, -- Thiago V. dos Santos
PhD studentLand and Atmospheric ScienceUniversity of Minnesota


On Thursday, July 27, 2017, 3:00:55 AM CDT, Dr. Benedikt Gräler <[hidden email]> wrote:

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/#/map


On 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
        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to objectively subset cities by population

Kent Johnson
In reply to this post by R-sig-geo mailing list
On Thu, Jul 27, 2017 at 10:11 AM, Thiago V. dos Santos <
[hidden email]> wrote:

> 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?
>

To my eye
  radius=~10*pmax(sqrt(Population), 100)
keeps the overlap manageable and makes the small cities a little bigger.

The advantage of leaflet vs plot is that you can easily zoom in to see the
smaller cities and click on them.

Kent


> 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 student
> Land and Atmospheric Science
> University 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]
> <[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
Loading...