ramnathv / rMaps

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

Browser not displaying custom topojson correctly #25

Open Koalha opened 10 years ago

Koalha commented 10 years ago

Thanks to @ekstroem's help here I was able to get my custom topojson to display with this code:

library(rMaps)

maps = Datamaps$new()

maps$set(
geographyConfig = list(
dataUrl="https://raw.github.com/Koalha/tryermap/master/kunnat2.topojson"
),

   scope = "Kunnatwgs",
setProjection = '#! function( element, options ) {
   var projection, path;
   projection = d3.geo.transverseMercator()
    .rotate([-27,-65,0])
    .scale(2000)
    .translate([element.offsetWidth / 2, element.offsetHeight / 2]);

   path = d3.geo.path().projection( projection );
   return {path: path, projection: projection};
  } !#'
)

maps

However, the map only displays in IE (not Chrome) on my computer, and has weird refreshing issues as shown by the image.

image

Could some one else also try this on their computer? Is there a way to easily fix this? What might be the cause?

lcolladotor commented 10 years ago

Works for me on Chrome Version 33.0.1750.146. I downloaded the topojson file and uploaded it in my public Dropbox folder to test it out as I was getting a console error when using raw.github

I also didn't see the weird refreshing issue you showed in the image

ramnathv commented 10 years ago

Thanks for checking out @lcolladotor . It works for me too. I suspect an older version of Chrome, or something to do with serving the file from raw.github, which usually doesn't work.

lcolladotor commented 10 years ago

No problem @ramnathv

Koalha commented 10 years ago

Raw.github seemed to be the problem. So many subtleties to work out, thank you very much for your help.

Not sure if it's proper conduct to keep asking stuff in this one thread, please inform if a new issue would be better.

I was wondering how does rMaps bind the map to the data? I now have a topojson file with an --id-property name, that corresponds with my data.frame:

head(rdat)

     name   vuosi   tiheys
1      Akaa  1980 53.78659
2  Alajärvi  1980 10.99292
3 Alavieska  1980 11.89529
4    Alavus  1980 12.47978
5  Asikkala  1980 14.64553
6    Askola  1980 19.10456

However, what I get when I run ichoropleth with tiheys~name is this:

image

,full code being this

What am I doing wrong?

yooper commented 10 years ago

Did you ever figure this issue out? I am having the same problem with rendering a map. I have been looking at the example http://lcolladotor.github.io/2014/02/26/excited-by-willingness-to-help-get-things-done/ and trying to compare and contrast the differences.

The difference I see is JSON output of the ichoropleth function differs from the above linked example and my code. In the above linked example ichoropleth function outputs JSON like this:

"newData": {
"1997": {
"Aguascalientes": {
"state_code": 1,
"year": 1997,
"type": "DOLOSOS",
"total": 355,
"population": 9.5813e+05,
"rate": 37.051,
"name": "Aguascalientes",
"fillKey": "(26.9,111]"
},

Where as my output from iChoropleth looks like this:

"newData": {
 "2009": {
 "1": {
 "name": "Alcona",
"total":    899,
"year": 2009,
"fillKey": "(4,1.2e+03]" 
},

For some reason my look up keys are numeric ie "1" when they should be the name such as "Alcona". Here is the head of my data frame:

> head(dat2)
     name total year fillKey
1  Alcona   899 2009       A
2   Alger  1144 2009       A
3 Allegan 17892 2009       H
4  Alpena  4572 2009       D
5  Antrim  3842 2009       D
6  Arenac  2469 2009       C

Any suggestions?

ramnathv commented 10 years ago

Your lookup keys showing up as numeric suggests that the name column is of the type factor. You can verify this by typing str(dat2) in your R console. To overcome this issue, you can simply transform the factor to a character by doing

dat2$name = as.character(dat2$name)

and then run your rMaps code.

Let me know if it solves the problem.

yooper commented 10 years ago

That fixed the problem. The name column was a factor. Running the command

dat2$name = as.character(dat2$name)

fixed the issue. Thank you!