[R-sig-Geo] Colors in package plotGoogleMaps

Milan Kilibarda kili at grf.bg.ac.rs
Tue Nov 29 21:44:03 CET 2011


Hi,

Just make categorical(factor) variable (V1) according to your threshold
and give  as new attribute (column) in dataframe, then set in
plotGoogleMaps colPalette=c(#FFFFFF,#000000) (2 colors), it is important
to set zcol="your factor variable" (V1).

For borders I didn't make it that easy like with polygon, I'll do it new
version soon, probably.

You can solve it like this. Make on the same way V2 as it described for
polygon fill. Than make string from V2
strokeColor=as.character(factor(V2,labels=c("color1","col2") ) colors
should be in hex notation (#FF0000 instead "red")

On the end your command should be something like this

plotGoogleMaps(nc,zcol="V1",colPalette=c(c1,c2 in hex
notation),strokeColor=as.character(factor(V2,labels=c("color1","col2") ))
)

And it should work, I hope :) .

Best regards,
Milan

> Hi Milan,
> thank for your reply to my  question.
> I think I wasn't clear saying what my problem is...
> I'd like to use 2  threshold (say T1 and T2) and to variables (say V1 and
> V2) and to have on the sampe map:
> polygons with color1 if V1 >T1, else color2;
> borders with color3 if V2>T2, else color4.
>
> I hope it's possible to do,
> thanks.
> Luca
>
>
>
> 2011/11/29 Milan Kilibarda <kili at grf.bg.ac.rs>
>
>> 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
>>
>>
>>
>


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