-1

This is the way I've organized my data to plot the map. I would like to have all points with the split label Night in one colour (let's say, blue) and all of the points with the label Day with a different colour (can't see Day on the sample below):

> head(times)
              DateTime  Latitude Longitude split
1: 2018-06-18 03:01:00 -2.434901  34.85359 Night
2: 2018-06-18 03:06:00 -2.434598  34.85387 Night
3: 2018-06-18 03:08:00 -2.434726  34.85382 Night
4: 2018-06-18 03:12:00 -2.434816  34.85371 Night
5: 2018-06-18 03:16:00 -2.434613  34.85372 Night
6: 2018-06-18 03:20:00 -2.434511  34.85376 Night

I've been trying to follow and modify codes from other posts here online but I'm having some trouble since I want my points to be labelled by colour. This is how far I got so far, now I just need some help to plot the points:

# creating a sample data.frame with your lat/lon points
lon <- times$Longitude
lat <- times$Latitude
df <- as.data.frame(cbind(lon,lat))

# getting the map
mapgilbert <- get_map(location = c(lon = mean(df$lon), lat = mean(df$lat)), zoom = 15,
                      maptype = "satellite", scale = 2)

# plotting the map, but don't know how to label points according to information on column "split"
ggmap(mapgilbert) +
  geom_point(data = df, aes(x = lon, y = lat, fill = "red", alpha = 0.8), size = 3, shape = 21) +
  guides(fill=FALSE, alpha=FALSE, size=FALSE)

Anyways, any input is appreciated.

Cheers

juansalix
  • 503
  • 1
  • 8
  • 21
  • 1
    Possible duplicate of [get\_map not passing the API key (HTTP status was '403 Forbidden')](https://stackoverflow.com/questions/52565472/get-map-not-passing-the-api-key-http-status-was-403-forbidden) – Dave2e Mar 13 '19 at 13:23
  • @Dave2e I've edited the post so that the question that resembled to the previous post you mentionned is deleted. I hope things are more clear now. – juansalix Mar 13 '19 at 14:25

1 Answers1

0

You could try leaflet:

times$color <- ifelse(times$split == "Night", "#000cff", "#ffa500")

lon <- times$Longitude
lat <- times$Latitude
split <- times$split
color <- times$color
df <- cbind(lon,lat,split,color)

m <- leaflet() %>%
    addTiles() %>%  # Add default OpenStreetMap map tiles
    addCircleMarkers(df, lng = lon, lat = lat, radius = 5, color = color,
               weight = 3, opacity = 1.0, fill = TRUE, fillColor = color,
               fillOpacity = 0.5, popup=split)
m

map with yellow/blue for day/night

cgrafe
  • 443
  • 1
  • 6
  • 14