使用不同的标签和颜色在R中绘制地图

问题描述 投票:-1回答:1

这是我组织数据绘制地图的方式。我想用split标签Night以一种颜色(比方说是蓝色)和所有带有不同颜色的标签Day的点(在下面的示例中看不到Day)得到所有点:

> 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

我一直在尝试在线跟踪和修改其他帖子中的代码,但我遇到了一些麻烦,因为我希望我的分数用颜色标注。这是我到目前为止的距离,现在我只需要一些帮助来绘制积分:

# 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)

无论如何,任何输入都表示赞赏。

干杯

r ggplot2 ggmap
1个回答
0
投票

你可以尝试传单:

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

© www.soinside.com 2019 - 2024. All rights reserved.