rgoogle-mapsgoogleway

R googleway: change marker colors


I have 2 data frames with the geocoded locations of several hospitals within the United States. I would like to plot these locations as markers with two different colors for each set of hospitals from each data frame. I am using the R googleway library and I can get the first set of hospitals to plot okay with a default red colored marker but when I try to change the color of the marker by defining the colour variable with the column names "col", I get the following error message "Error in markerColourIconCheck(data, objArgs, colour, marker_icon) : colours must be either red, blue, green or lavender"

The column "col" is "green" in every row. I tried filling in the hexadecimal color for green in the column "col" as well. so this piece of code works with red markers

google_map(key = key, data = hem_centers) %>%
add_markers()

This doesn't

google_map(key = key, data = hem_centers) %>%
add_markers(colour = "col")

Any suggestions on how to fix it?

Also can I add the markers from the first data frame and then layer on the markers from the second data frame (in a different color)? Something like this:

google_map(key = key) %>%
add_markers(data = hem_centers, colour = "col") %>%
add_markers(data = other_centers, colour = "col")

Appreciate any suggestion. Thanks!


Solution

  • I just ran this code and it worked

    #install.packages("googleway")
    library(googleway)
    
    set_key( "GOOGLE_MAP_KEY" )
    
    tram_stops$colour <- sample(c("green","blue","lavender"), size = nrow(tram_stops), replace = T)
    
    google_map() %>%
        add_markers(
            data = tram_stops
            , colour = "colour"
        )
    

    enter image description here