I'm producing a kml file with several layers. Within each layer, I'm colour-coding the points based on a sub-grouping. I'm struggling with a few things:
- all layers are named "SpatialPointsDataFrame" in the kml, and I can't figure out how to assign layer names directly.
- The label size on the points is very small - is there a way to make it larger?
- Ideally, within each layer, I would have 2 sublayers based on the subgroups, so that the whole subgroup can be selected or de-selected. Is it possible to control layer hierarchy?
Toy example:
library(dplyr)
library(sp)
library(plotKML)
# generate spatial data with 2 groups (A, B) and two subgroups (C, D) within each group
df <- data.frame(x = rnorm(10, 493388, 50), y = rnorm(10, 5701483, 50)) %>%
mutate(Group = sample(c("A", "B"), 10, replace = TRUE),
Running = 1:n()) %>%
group_by(Group) %>%
mutate(Subgroup = sample(c("C", "D"), n(), replace = TRUE)) %>%
ungroup()
kml_open("try.kml")
for(i in unique(df$Group)){
sub <- df %>%
filter(Group == i)
coordinates(sub) <- ~x+y
proj4string(sub) <- CRS("+proj=utm +zone=11 +ellps=WGS84")
kml_layer(sub, name = i, shape = "http://plotkml.r-forge.r-project.org/circle.png",
size = 1, colour=Subgroup, colour_scale = c("yellow", "red"),
labels = Running)
}
kml_close("try.kml")