[英]R cran ggplot print map
I am trying to print an R map with the following function (see at bottom) The input is a data frame that contain Longitude, Latitudes in decimal format and the errors that would be depicted as color bullet points. 我正在尝试使用以下功能打印R地图(请参阅底部)输入是一个数据框,其中包含经度,十进制格式的纬度以及将被描述为彩色项目符号点的错误。
This works quite okay but I want to add a new extra point, apart of what the data frame includes, that would have a different type (instead of dot, perhaps a cross or a square) and with a fixed red color, instead of following the color ramp I have for the rest of the points. 这项工作还可以,但是我想添加一个新的额外点,除了数据框所包含的点之外,该点将具有不同的类型(而不是点,可能是十字或正方形)并且具有固定的红色,而不是跟随其余各点的色阶。
Can you please help me sort this out? 你能帮我解决这个问题吗? Regard Alex
问候亚历克斯
dfE<-data.frame(c(-0.1456250,-0.1442639),c(51.51476,51.51492),c(0.018878676,0.111847050))
names(dfE) <- c("Longitude", "Latitude", "Error")
stationaryPoint<-data.frame(0.1422361,51.51516)
names(stationaryPoint) <- c("Longitude", "Latitude")
data<-dfE
jet.colors <- colorRampPalette(c("#00007F", "red", "#007FFF", "yellow", "#7FFF7F", "cyan", "#FF7F00", "blue", "#7F0000"))
bbox <- c(min(data[, 1])-0.001, min(data[, 2])-0.001, max(data[, 1])+0.001, max(data[, 2])+0.001)
mp <- get_stamenmap(bbox, maptype = "toner", zoom = zoom)
ggmap(mp, darken = 0) + geom_point(aes(Longitude, Latitude, colour =Error), data = dfE, size = 3)
I tried adding the below line to add the extra point with different color and shape to the ggmap line before but I always get an error 我尝试添加以下行以在ggmap线之前添加具有不同颜色和形状的额外点,但是我总是收到错误
Since you didn't provide any data it is difficult to help you. 由于您未提供任何数据,因此很难为您提供帮助。
The solution to your problem could be to add another layer with geom_point
: 解决您的问题的方法可能是使用
geom_point
添加geom_point
:
# create new data.frame with location of point you want to plot
newdata <- data.frame(Longitude = c(40.7143528), Latitude = c(-74.0059731)) # New York
ggmap(mp, darken = 0) +
geom_point(aes(Longitude, Latitude, colour =Error), data = dfE, size = 3) +
geom_point(data = newdata, shape = 15) +
RestofyourCode
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.