Dear Luca,
It is not difficult to set colors by attributes. According to your example.
plotGoogleMaps(nc,zcol="NWBIR74",filename='MyMap.htm',mapTypeId='TERRAIN',colPalette=rainbow(5))
It sets colors by argument NWBIR74 . It makes 5 categories of argument
NWBIR74 and gives colors from rainbow palette. It is better to use
palettes from RColorBrewer package.
If you want to set border color just add strokeColor="red" e.g.:
plotGoogleMaps(nc,zcol="NWBIR74",filename='MyMap.htm',mapTypeId='TERRAIN',colPalette=rainbow(5),strokeColor="red")
If you want to create new argument in form of factor you then just need to
set colPallete colors which has the same number of colors as levels of
your categories (factor argument).
I hope it helps.
Milan
> Hi everybody,
> I'm trying to use colPalette and/or strokeColor arguments in the function
> plotGoogleMaps to have different colors for values in the data.frame
> columns.
> I can't get the correct map, and always get a warning message.
> I tried the following (reproducible) code:
>
> library(maptools)
> library(rgdal)
> library(plotGoogleMaps)
>
> nc <- readShapePoly(system.file("shapes/sids.shp",
> package="maptools")[1], proj4string=CRS("+proj=longlat +datum=NAD27"))
>
> #First I tried colouring polygons and border differently...
> nc1=nc
> nc1@data=data.frame(City_Name=nc@data$NAME,NWBIR74=nc@data
> $NWBIR74,BIR74=nc@data$BIR74)
> nc1Fill=rep("green",length(nc1@data$City_Name))
> nc1Bord=nc1Fill
> nc1Fill[nc1@data$NWBIR74>300]="red"
> nc1Bord[nc1@data$BIR74>2000]="yellow"
> nc1Bord[nc1@data$BIR74>10000]="red"
>
> MaiMap<-
> plotGoogleMaps(nc1,filename='MyMap.htm',mapTypeId='TERRAIN',colPalette=nc1Fill,strokeColor=nc1Bord)
> #here I get the following warning message:
> #In `levels<-`(`*tmp*`, value = c("green", "green", "green", "green", :
> # duplicated levels will not be allowed in factors anymore
>
> #borders are all green
>
>
> #Than I tried with 2 layers, as here:
> nc1=nc
> nc1@data=data.frame(City_Name=nc@data$NAME,NWBIR74=nc@data$NWBIR74)
> nc1Fill=rep("green",length(nc1@data$City_Name))
> nc1Fill[nc1@data$NWBIR74>300]="red"
> nc2=nc
> nc2@data=data.frame(City_Name=nc@data$NAME,BIR74=nc@data$BIR74)
> nc2Fill=rep("green",length(nc2@data$City_Name))
> nc2Fill[nc2@data$BIR74>2000]="yellow"
> nc2Fill[nc2@data$BIR74>10000]="red"
>
> MaiMap1<- plotGoogleMaps(nc1,mapTypeId='TERRAIN',colPalette=nc1Fill,
> add=TRUE)
> MaiMap2<-
> plotGoogleMaps(nc2,filename='MyMap.htm',colPalette=nc2Fill,previousMap=MaiMap1)
> #here I get the same error , but map colors are wrong.
>
> Any suggestion?
> Thanks,
> Luca.
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [email protected]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
Milan Kilibarda
University of Belgrade,
Faculty of Civil Engineering,
Department of Geodesy and Geoinformatics,
Address: Bulevar kralja Aleksandra 73
11000 Belgrade, Serbia,
Mail:[email protected]
tel:+381 11 3218516
_______________________________________________
R-sig-Geo mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo