[R-sig-Geo] Colors in package plotGoogleMaps

Milan Kilibarda kili at grf.bg.ac.rs
Tue Nov 29 16:37:06 CET 2011


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 at data=data.frame(City_Name=nc at data$NAME,NWBIR74=nc at data
> $NWBIR74,BIR74=nc at data$BIR74)
> nc1Fill=rep("green",length(nc1 at data$City_Name))
> nc1Bord=nc1Fill
> nc1Fill[nc1 at data$NWBIR74>300]="red"
> nc1Bord[nc1 at data$BIR74>2000]="yellow"
> nc1Bord[nc1 at 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 at data=data.frame(City_Name=nc at data$NAME,NWBIR74=nc at data$NWBIR74)
> nc1Fill=rep("green",length(nc1 at data$City_Name))
> nc1Fill[nc1 at data$NWBIR74>300]="red"
> nc2=nc
> nc2 at data=data.frame(City_Name=nc at data$NAME,BIR74=nc at data$BIR74)
> nc2Fill=rep("green",length(nc2 at data$City_Name))
> nc2Fill[nc2 at data$BIR74>2000]="yellow"
> nc2Fill[nc2 at 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
> R-sig-Geo at r-project.org
> 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:kili at grf.bg.ac.rs

tel:+381 11 3218516



More information about the R-sig-Geo mailing list