Actuarial Outpost

Actuarial Outpost (http://www.actuarialoutpost.com/actuarial_discussion_forum/index.php)
-   Property - Casualty / General Insurance (http://www.actuarialoutpost.com/actuarial_discussion_forum/forumdisplay.php?f=14)
-   -   mapping in R (cat modelling?) (http://www.actuarialoutpost.com/actuarial_discussion_forum/showthread.php?t=328840)

ronaldy27 12-20-2017 09:44 AM

mapping in R (cat modelling?)
 
Hi,
I am trying to find a way to organize all the insureds by where they live within the US, perhaps group them by a fixed area using Longitude and Latitude so that if a natural disaster were to happen in certain regions, I can analyse the "total insureds value" impact on the insureds located in the areas.

I went over documentations for some mapping packages in R but I am kind of lost. I know the "maps" allow you to group regions by counties, states,etc. However, is there a way for me to add data into those regions?

I'm a newbie in R and I would appreciate it if anyone could provide me with a direction as to how to go about this project.

Klaymen 12-20-2017 10:04 AM

Although I use the maps package, it is not very sophisticated. It gets me nice color maps by state and county, and I can lay overlay text or values and show a title and a legend.
I would like to learn the more sophisticated methods but it just hasn't been worth the time to me yet. I doubt that it will adequately meet your needs (i.e. lat and long), but it is an easy place to get started. I think you'll want ggplot2 but there is much more involved. (if someone else wants to provide code I would appreciate it)

Here's some sample code for the maps program. Copying the information directly from the screen didn't look right but if you go to the source of this message (quote it) it should work.

library(maps)
library(mapdata)

countycol<-cbind(
"#b35806","#b35806","#b35806","#d8daeb","#fee0b6","#fee0b6","#998ec3","#998ec3","#542788","#d8daeb","#b35806","#f1a340","#b35806","#d8daeb","#542788","#542788","#998ec3","#f1a340","#998ec3","#fee0b6","#b35806","#f1a340","#b35806","#b35806","#b35806","#d8daeb","#d8daeb","#542788","#fee0b6","#f1a340","#b35806","#b35806","#542788","#f1a340","black","#542788","#542788","#b35806","#f1a340","#b35806","#b35806","#998ec3","#f1a340","#b35806","#d8daeb","#f1a340","#542788","#998ec3","#fee0b6","#542788","#998ec3","#b35806","#f1a340","#998ec3","#fee0b6","#b35806","#542788","#b35806","#b35806","#fee0b6","#d8daeb","#542788","#542788","#d8daeb","#b35806","#542788","black","#d8daeb","#d8daeb","#d8daeb","#d8daeb","black","#fee0b6","#b35806","#f1a340","#d8daeb","#f1a340","black","#542788","#998ec3","#542788","#d8daeb","#b35806","#f1a340","#542788","#b35806","#d8daeb","#d8daeb","#b35806","#f1a340","#f1a340","#542788","#998ec3","#542788","#542788","#542788","#542788","#998ec3","#b35806","#b35806","#542788","#f1a340","#d8daeb","black","#f1a340","#b35806","#f1a340","#f1a340","#fee0b6","#542788","#542788","#542788","#f1a340","#b35806","#f1a340"
)

map('county','missouri',fill=TRUE,col=countycol)
title("American Family Missouri Outbuilding Relativities")
map.text('county','missouri',col="black",add=TRUE,cex=0.50)
legend(x='topright',legend = c("1.00","1.249","1.343","1.737","2.252","3.465","N/A"),cex=1.00,
fill=cbind(
"#542788",
"#998ec3",
"#d8daeb",
"#fee0b6",
"#f1a340",
"#b35806",
"black"
))

ronaldy27 12-20-2017 10:08 AM

Quote:

Originally Posted by Klaymen (Post 9195641)
Although I use the maps package, it is not very sophisticated. It gets me nice color maps by state and county, and I can lay overlay text or values and show a title and a legend.
I would like to learn the more sophisticated methods but it just hasn't been worth the time to me yet.

Yeah, I'm a newbie in this and even I knew maps was not going to help me get far. I did find another documentation for mapping in R: "Introduction to visualising spatial data in R"

This one went a little more in depth.

ronaldy27 12-20-2017 10:14 AM

https://www.coursera.org/learn/r-data-visualization

Starts on Dec 25, on Christmas, if anyone is as lonely as I am and is interested in learning about mapping.

This might help me do this project.

Klaymen 12-20-2017 10:59 AM

nice humblebrag about being lonely.

Tacoactuary 12-20-2017 11:11 AM

1 Attachment(s)
In just the past few months I built a Shiny app to help visualize information related to a territorial rate review. It uses leaflet for interactive choropleths and plotly for interactive graphs. Let me know if you have any questions.

ronaldy27 12-20-2017 12:04 PM

Quote:

Originally Posted by Tacoactuary (Post 9195770)
In just the past few months I built a Shiny app to help visualize information related to a territorial rate review. It uses leaflet for interactive choropleths and plotly for interactive graphs. Let me know if you have any questions.

That's some good stuff. I didn't even know what "Shiny" was until now.
I found a website with tutorial videos. Are they completely free?

cowactuary 12-20-2017 12:16 PM

Look at the ggmap package

Tacoactuary 12-20-2017 12:24 PM

Quote:

Originally Posted by ronaldy27 (Post 9195841)
That's some good stuff. I didn't even know what "Shiny" was until now.
I found a website with tutorial videos. Are they completely free?

Yes. Shiny, leaflet, and plotly are open source under various licenses of and free for commercial use subject to each licence's requirements.

clarinetist 12-20-2017 05:38 PM

I was using ggmap for a while, but I've stuck with using D3.js for mapping.


All times are GMT -4. The time now is 09:48 AM.

Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

Page generated in 0.13108 seconds with 9 queries