ramnathv / rMaps

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

Labels and legend in ichoropleth #23

Open ekstroem opened 10 years ago

ekstroem commented 10 years ago

Hi all, I am trying to get a custom map of Danish counties to show with rMaps but have run into two problems:

Here's my code (apart from the input data) and the output can be seen at http://biostatistics.dk/pics/dkmap.html

library(rCharts)
library(rMaps)

options(RCHART_WIDTH = 600, RCHART_HEIGHT = 600)
options(rcharts.cdn = TRUE)

indata <- read.table("middelleveltid.txt", col.names=c("kommune", "life"), as.is=TRUE, na.string="..")
indata[is.na(indata)] <- 0
indata$extra <- 1:99

d1 <- ichoropleth(life ~ kommune, data = indata, ncut=8, map='states')
d1$set(
       geographyConfig = list( dataUrl = "/home/claus/sandbox/dk_kom.json" ),
       scope = 'states',
       legend = TRUE, 
       labels = TRUE,
       setProjection = '#! function( element, options ) {
           var projection, path;
           projection = d3.geo.mercator()
           .center([10, 56]).scale(element.offsetWidth*9)
           .translate([element.offsetWidth / 2, element.offsetHeight / 2]);

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

d1$print('chart4', include_assets = TRUE)

I thought that the legend and labels arguments to ichoropleth would add the legend and additional data information to the map, but there seems to be no difference in the output if I set them to TRUE or FALSE. Since they even have default values in ichoropleth I'm not even sure if I need to reset them again in the call to set or if the default values will still be inherited from the environment of d1.

Cheers,

Claus