I have a data frame (X) that looks like this:
code cluster name longt latit
101 1 A -89.6171 35.24992
105 1 B -90.0154 35.10510
106 2 C -89.5213 34.93277
111 1 D -86.8642 36.34807
113 3 E -86.6125 36.19958
114 2 F -90.4611 30.02196
I would like to plot the observations based on the cluster using plotGoogleMaps
function. I have done the following:
X1 <- X
coordinates(X1) <- ~longt+latit # convert to SPDF
proj4string(X1) <- CRS("+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0")
ic <- iconlabels(X1$cluster, height=10,colPalette=rainbow(4), icon=TRUE)
m <- plotGoogleMaps(X1,filename='myMap.htm', iconMarker=ic,
colPalette=rainbow(4),mapTypeId='ROADMAP',layerName = 'Clusters')
But I am facing two problems:
when I use
rainbow(3)
as colors, I get only 2 colors in my legend (instead of 3). But when I use rainbow(4), I get 4 colors.The legend doesn't represent the clusters, i.e. I don't get a color for each cluster (like one color for #1, one color for #2, one color for #3,...)
The Icons plotted on google map are only 2 colors (Green and Red). Clusters 1 and 2 are all red, and cluster 3 is green. I would like to obtain a distinct color for each cluster.