SymbolixAU / googleway

R Package for accessing and plotting Google Maps
http://symbolixau.github.io/googleway/
Other
232 stars 46 forks source link

variable to define column in `data` #168

Closed SymbolixAU closed 4 years ago

SymbolixAU commented 6 years ago

By design using a variable as a column identifier doesn't work. Maybe it should in the next release?

map_key <- read.dcf("~/Documents/.googleAPI", fields = "GOOGLE_MAP_KEY")
df <- melbourne[1:3,]
df$rand <- as.character(rnorm(nrow(df)))
iw <- "rand"
google_map(key = map_key) %>%
  add_polygons(
    data = df
    , polyline = "polyline"
    , info_window = iw
    , id = "polygonId"
)

So if the variable refers to a column in the data.frame it's recognised as such.

related #182

avsdev-cw commented 5 years ago

This would bring googleway parameters more in line with other common libraries such as ggplot2

SymbolixAU commented 5 years ago

Yes it would. However, I'm going to re-design the whole library in a few weeks, so it might take a while to get working / right.

tradeli commented 5 years ago

Is there a way to circumvent this behavior ? Using some form of quasiquotation or quick workarround to make it support variables? @SymbolixAU

SymbolixAU commented 5 years ago

I've made a "variables" branch where you can test out this functionality

devtools::install_github("SymbolixAU/googleway", ref = "variables" )

This is now working for me

library(googleway)

set_key( "GOOGLE_MAP_KEY")

col <- "stop_name"
myPoly <- "polyline"
polyColour <- "SA2_NAME"

google_map() %>%
  add_circles(
    data = tram_stops
    , fill_colour = col
  ) %>%
  add_markers(
    data = tram_stops
  ) %>%
  add_polygons(
    data = melbourne
    , polyline = myPoly
    , fill_colour = polyColour
  )

Please let me know if you have any issues.

tradeli commented 5 years ago

It works! Thank you very much!

dcooley commented 4 years ago

got completely sidetracked so never got around to redesigning this. However, I've now merged the variables branch into master.