Skip to content
Prev 383883 / 398502 Next

Help with map()

Hello Jim, et.al, again.

One last question please.

Since this routine works best with larger volume of geo points, is there a way to modify this routine to accommodate more than one cluster and differentiated by different colors?

#Single cluster routine
clus3 <- individual_dets_sf_3X %>% 
  
  dplyr::select(MBR_SUBSCRIBERID,state,city,clusters,Latitude,Longitude,distances_Mi) %>% #Notice now that these are capitalized <--"L"
  
  filter(clusters == 3)

str(clus3)

clus3 <- as.data.frame(clus3)

geomat<-makeDensityMatrix(clus3[,c("Latitude","Longitude")],
                          xlim=range(clus3$Longitude),ylim=range(clus3$Latitude))
# Range of density (>0) - 1.292155 3.89646 
latlim<-range(clus3$Latitude)
lonlim<-range(clus3$Longitude)

map("world",xlim=lonlim,ylim=latlim)
axis(1)
axis(2)
densityGrid(geomat,range.cex=c(1,5),xlim=lonlim,ylim=latlim,
            red=c(0.5,1),green=0,blue=0,pch=15)
title("Member Geo Density Plot For Cluster3")

knitr::kable(individual_dets_sf_3X %>% group_by(clusters) %>% tally(sort = TRUE))

#   | clusters|   n|
#   |--------:|---:|
#   |        3| 384|
#   |        5| 335|
#   |        9| 305|
#   |        7| 298|
#   |       10| 286|
#   |        6| 279|
#   |        4| 168|
#   |        8| 131|
#   |        2| 113|
#   |        1|  53|

'data.frame':	384 obs. of  7 variables:
 $ MBR_SUBSCRIBERID: Factor w/ 2352 levels "101040199600",..: 908 2272 1613 1357 1952 1437 795 1634 1160 902 ...
 $ state           : Factor w/ 41 levels "AL","AR","AZ",..: 10 23 23 10 33 10 10 23 10 10 ...
 $ city            : Factor w/ 1337 levels "ABBOTTSTOWN",..: 156 496 354 827 670 1161 897 970 249 494 ...
 $ clusters        : num  3 3 3 3 3 3 3 3 3 3 ...
 $ Latitude        : num  31.2 35.3 36.5 33.4 34.2 ...
 $ Longitude       : num  -81.5 -82.4 -81 -84.7 -80.7 ...
 $ distances_Mi    : num  770 586 471 769 573 ...





Proprietary

-----Original Message-----
From: Poling, William 
Sent: Thursday, May 14, 2020 7:03 AM
To: Jim Lemon <drjimlemon at gmail.com>
Cc: r-help at r-project.org; Mark Fowler <gmark.fowler at outlook.com>
Subject: RE: [EXTERNAL] Re: [R] Help with map()

Hi, it is working now using just the most necessary pkgs.

 Evidently when there are so few rows (clus1=53) the map does not cooperate, I get the plot but no map image?

As I increase records the map begins to appear as it did for Radius1-8 routines

Thank you for your time and trouble my friends.

WHP





Proprietary

-----Original Message-----
From: Poling, William 
Sent: Thursday, May 14, 2020 6:46 AM
To: Jim Lemon <drjimlemon at gmail.com>
Cc: r-help at r-project.org; Mark Fowler <gmark.fowler at outlook.com>
Subject: RE: [EXTERNAL] Re: [R] Help with map()

Hi, I ran this which is partially successful. I got long & lat  (x&y) with red plot values however, no map behind it?

Not sure what I might be missing now in terms of pkgs I suppose?
#Just use the basic pkgs
library(magrittr)#for %>% function
library(plotrix)
library(maps)
library(dplyr)#For filter()
str(individual_dets_sf_3X)
str(radius3)
str(clus1)


#rm(clus1)

clus1 <- individual_dets_sf_3X %>% 
  
  dplyr::select(MBR_SUBSCRIBERID,state,city,clusters,Latitude,Longitude,distances_Mi) %>% #Notice now that these are capitalized <--"L"
  
  filter(clusters == 1)

str(clus1)

clus1 <- as.data.frame(clus1)

geomat<-makeDensityMatrix(clus1[,c("Latitude","Longitude")],
                          xlim=range(clus1$Longitude),ylim=range(clus1$Latitude))
# Range of density (>0) - 1.292155 3.89646 
latlim<-range(clus1$Latitude)
lonlim<-range(clus1$Longitude)

map("world",xlim=lonlim,ylim=latlim)
axis(1)
axis(2)
densityGrid(geomat,range.cex=c(1,5),xlim=lonlim,ylim=latlim,
            red=c(0.5,1),green=0,blue=0,pch=15)
title("Member Geo Density Plot For Cluster1")





Proprietary

-----Original Message-----
From: Poling, William 
Sent: Thursday, May 14, 2020 6:29 AM
To: Jim Lemon <drjimlemon at gmail.com>
Cc: r-help at r-project.org; Mark Fowler <gmark.fowler at outlook.com>
Subject: RE: [EXTERNAL] Re: [R] Help with map()


Hi Jim, and Mark, thank you for your response.

1. I have restarted R
2. I have only initiated library(magrittr)#for %>% function & library(plotrix), no other libraries thinking that another may be overwriting something.
3. I have checked the str()

str(radius3)
'data.frame':	1990 obs. of  6 variables:
 $ MBR_SUBSCRIBERID: Factor w/ 2352 levels "101040199600",..: 590 908 976 509 1674 690 1336 726 1702 2331 ...
 $ state           : Factor w/ 41 levels "AL","AR","AZ",..: 32 10 25 11 9 32 13 12 12 17 ...
 $ city            : Factor w/ 1337 levels "ABBOTTSTOWN",..: 932 156 230 698 965 1330 515 1127 1304 1316 ...
 $ Latitude        : num  40.4 31.2 40.8 42.1 26.8 ...
 $ Longitude       : num  -79.9 -81.5 -74 -91.6 -82.1 ...
 $ distances_Mi    : num  310.3 769.9 16.1 920.4 1057.6 ...

str(clus1)
tibble [53 x 7] (S3: tbl_df/tbl/data.frame)  $ MBR_SUBSCRIBERID: Factor w/ 2352 levels "101040199600",..: 86 2111 995 899 953 924 769 92 790 1748 ...
 $ state           : Factor w/ 41 levels "AL","AR","AZ",..: 31 39 4 39 39 39 39 31 39 39 ...
 $ city            : Factor w/ 1337 levels "ABBOTTSTOWN",..: 727 85 455 1018 1203 604 1169 727 984 295 ...
 $ clusters        : num [1:53] 1 1 1 1 1 1 1 1 1 1 ...
 $ Latitude        : num [1:53] 42.4 47.6 39.2 46.9 48 ...
 $ Longitude       : num [1:53] -123 -122 -121 -123 -122 ...
 $ distances_Mi    : num [1:53] 2499 2406 2472 2430 2408 ...

4. I change clus1 to DF
'data.frame':	53 obs. of  7 variables:
 $ MBR_SUBSCRIBERID: Factor w/ 2352 levels "101040199600",..: 86 2111 995 899 953 924 769 92 790 1748 ...
 $ state           : Factor w/ 41 levels "AL","AR","AZ",..: 31 39 4 39 39 39 39 31 39 39 ...
 $ city            : Factor w/ 1337 levels "ABBOTTSTOWN",..: 727 85 455 1018 1203 604 1169 727 984 295 ...
 $ clusters        : num  1 1 1 1 1 1 1 1 1 1 ...
 $ Latitude        : num  42.4 47.6 39.2 46.9 48 ...
 $ Longitude       : num  -123 -122 -121 -123 -122 ...
 $ distances_Mi    : num  2499 2406 2472 2430 2408 ...

Then try again, no luck?

Weird?

Thanks

WHP

Proprietary

-----Original Message-----
From: Jim Lemon <drjimlemon at gmail.com>
Sent: Thursday, May 14, 2020 5:44 AM
To: Poling, William <PolingW at aetna.com>
Cc: r-help at r-project.org
Subject: [EXTERNAL] Re: [R] Help with map()

**** External Email - Use Caution ****

Hi Bill,
Have you compared str(radius3) to str(clus1)? It may be quite different.

Jim
On Thu, May 14, 2020 at 8:24 PM Poling, William via R-help <r-help at r-project.org> wrote:
NOTICE TO RECIPIENT OF INFORMATION:
This e-mail may contain confidential or privileged information. If you think you have received this e-mail in error, please advise the sender by reply e-mail and then delete this e-mail immediately.  
This e-mail may also contain protected health information (PHI) with information about sensitive medical conditions, including, but not limited to, treatment for substance use disorders, behavioral health, HIV/AIDS, or pregnancy. This type of information may be protected by various federal and/or state laws which prohibit any further disclosure without the express written consent of the person to whom it pertains or as otherwise permitted by law. Any unauthorized further disclosure may be considered a violation of federal and/or state law. A general authorization for the release of medical or other information may NOT be sufficient consent for release of this type of information.
Thank you. Aetna
Message-ID: <BYAPR06MB5383ECACAEE69771084F4699AEBC0@BYAPR06MB5383.namprd06.prod.outlook.com>
In-Reply-To: <BYAPR06MB538355DBADC052E34DA1D3D8AEBC0@BYAPR06MB5383.namprd06.prod.outlook.com>