ramnathv / rMaps

Interactive Maps from R
http://rmaps.github.io
389 stars 194 forks source link

Crosslet question #7

Open smach opened 10 years ago

smach commented 10 years ago

Is it possible yet to reproduce a map such as this one in rMaps (using just R, without adding JavaScript)?

http://sztanko.github.io/crosslet/examples/us/

I'm not sure how one would do in rMaps data inputs such as

geo: {
      url: "data/us_counties.topo.json",
      name_field: "NAME",
      id_field: "GEOID",
      topo_object: "us_counties"
    }
  },
  data: {
    version: "1.0",
    id_field: "fips"
  },
  dimensions: {
    total: {
      title: "Population",
      data: {
        dataSet: "data/us_elect_county.csv",
        field: "total"
      },
ramnathv commented 10 years ago

Yes. It is possible to do US counties out of the box. This is not to be used for production as yet mainly for two reasons. One, I am using a rawgithub link to load the us counties topojson, which is only fair for local use. Two, I have hardcoded a cloudmade map api key, which needs to be made an option. I have solved both issues and will be pushing a fix to github shortly.

dat = read.delim('us_elect_county.csv', colClasses = 'character')
dat[,4:10] = apply(dat[,4:10], 2, as.numeric)

crosslet(
  x = "fips",
  y = c('obama_p', 'romney_p'),
  data = dat,
  map = 'usa'
)
smach commented 10 years ago

Thanks! Certainly won't use on our live site yet then! I was thinking to demo at a hands-on session with 20 or so attendees in a couple of weeks, though.

ramnathv commented 10 years ago

I will be pushing an updated version with a blog post on using crosslet by end of this week.

smach commented 10 years ago

FYI I don't actually get a map to show up when I run the code above, although I do when I run the other crosslet() example here. I just get a gray background although the sliders are showing up with the appropriate numbers. I'm not sure if it's not understanding these fips codes as county polygons?

ramnathv commented 10 years ago

I will be pushing an update this weekend which will make it easier to work with crosslet. I will add the US counties example and also show how to use custom maps.

jhollist commented 10 years ago

@ramnathv I was going to ask about a similar thing (based on our conversation over at the rOpenSci Hackathon repo. But I see you already have plans to tackle this. I will patiently await the custom maps example!

ramnathv commented 10 years ago

@jhollist I should be pushing this by end of this week. I don't use any GIS myself, so would be very interesting to learn more about what features are useful and what are not. As I indicated in my response earlier, my vision for rMaps is to allow users to be able to create interactive maps without having to worry about the back-end (shapefiles, kml, geojson etc) or the front-end (leaflet, mapbox, google maps etc.), thereby giving a lot of flexibility.

jhollist commented 10 years ago

@ramnathv I've been using GIS for a longtime (going on 20 years I think. Yikes.). So, I'd be happy to help out in that regard how ever I can. Just let me know where you think I could be helpful.

I did get a chance to start playing around with rMaps this morning. I was using Leaflet and got the map to draw, but didn't get my SpatialPolygonsDataFrame to render. Tried converting both to KML and GeoJSON. From the looks of it I needed to hack some .js and that is what you are currently working on. As I said, I'll wait till you get that finished up.

One possible issue will be projections. Most of the data I work with is projected and not in geographic coordinates. The function I was working on this AM simply reprojected to decimal degrees. That is one way to go. However, it would also be nice to display data in the original projected coordinates.

In any event, I could envision two types of users. Those wanting to make maps with basic spatial information (current focus, I would guess) and those wanting to mimic some basic GIS functionality and plot their own spatial data. I think rMaps could easily provide for both user groups.