When constructing a R code, for example, for plotting some stuff, often it is necessary to add subsequent "layers" (labels, axes, markers) etc coded with complicated expressions. The example here comes from the "leaflet" package, and layers are added via a pipe operator %>%:
library("leaflet")
library("leaflet.minicharts")
mymap <- leaflet() %>% addTiles() %>% addMinicharts(0, 0, chartdata = 1:3, layerId = "c1")
I want now to add some complicated stuff:
mymap %>% addCircleMarkers(0,0,radius=10,labelOptions=labelOptions(noHide=T,textOnly=TRUE,direction="bottom", offset=c(0,5)))
I would like to assign a short name to such construction, lets say, "mycircle", and then use it in the command:
mymap %>% mycircle
How it is possible to do so? Assigning via mycircle<-addCircleMarkers(0,0,....) does not work
Try this:
mymap <- leaflet() %>% addTiles() %>%
addMinicharts(0, 0, chartdata = 1:3, layerId = "c1")
mycircle <- function(x) {
addCircleMarkers(map=x, 0, 0, radius=10,
labelOptions=labelOptions(
noHide=T, textOnly=TRUE, direction="bottom", offset=c(0,5)))
}
mymap %>% mycircle