在没有边框的地图上绘制点

时间:2016-04-06 20:59:55

标签: r ggplot2 ggmap

library(ggplot2)
library(ggmap)
data <- read.table(file = "data.txt", sep = ",", col.names = c("lat", "lon", "place_name"), fill=FALSE, strip.white=TRUE)

# getting the map
mapgilbert <- get_map(location = c(lon = mean(data$lon), lat = mean(data$lat)),
              zoom = "auto" , maptype = "roadmap", scale = 2, color = "bw")

# plotting the map with some points on it
ggmap(mapgilbert, extent = "device") +
  geom_point(data = data, aes(x = lon, y = lat, fill = place_name), size = 0.5, shape = 22) +
  guides(fill=FALSE, alpha=FALSE, size=FALSE)

这将产生不同颜色的点(根据其名称)。像这样:

enter image description here

但是,我想摆脱积分的黑色边框。有没有办法做到这一点?

1 个答案:

答案 0 :(得分:4)

尝试使用其他shape

data <- data.frame(lat=52.5176736, lon=13.3895097)
library(ggmap)
library(ggplot2)
mapgilbert <- get_map(location = c(lon = mean(data$lon), lat = mean(data$lat)),
              zoom = "auto" , maptype = "roadmap", scale = 2, color = "bw")
ggmap(mapgilbert, extent = "device") +
  geom_point(data = data, aes(x = lon, y = lat), size = 6, shape = 16, color="red") +
  guides(fill=FALSE, alpha=FALSE, size=FALSE)

或使用color时将NA设置为shape = 21

ggmap(mapgilbert, extent = "device") +
  geom_point(data = data, aes(x = lon, y = lat), size = 6, shape = 21, color=NA, fill = "red") +
  guides(fill=FALSE, alpha=FALSE, size=FALSE)

enter image description here