0
votes

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.

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

  • geom_point(aes(Longitude, Latitude), data = stationaryPoint, size = 3,shape=4,color="red")
1
please supply your data with dput(data). - Thomas K
thanks added them on my inital post - Alex
I still can not reproduce your graph. Please make a truly reproducible example, i.e. an example, where I just copy the code and it works up to the point where you need help. - Thomas K
Thanks. added code above. You might only need to load the ggmap library - Alex

1 Answers

0
votes

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:

# 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