0
votes

I have the following graph:

dat<-data.frame(name=c("a","b","c"), x=1:3, y=1:3)
ggplot(dat, aes(x=x, y=y))+
geom_point(aes(shape=paste(1:3,": point",name)))+
geom_text(aes(x=x,y=y+0.07), label=1:3)+
scale_shape_manual(values=rep(1,3))+
labs(shape="locations")

I need to add the points to ggmap, however when i get rid of ggplot and start with : geom_point(dat, aes(x=x, y=y,shape=paste(1:3,": point",name)))+

I get an error"Error: Discrete value supplied to continuous scale"

1
ggplot(dat, ...) defines dat as the default dataset, referenced in all the following geom_* calls. If you move that to geom_point(data=dat,...), then geom_text(...) does not know what to use for data. Can you provide a more complete question which shows the use of ggmap(....)jlhoward
geom_point(dat, aes(x=x, y=y,shape=paste(1:3,": point",name)))+ geom_text(dat, ,aes(x=x,y=y+0.07), label=1:3)+ scale_shape_manual(values=rep(1,3))+ labs(shape="locations") I get an error that "Discrete value supplied to continuous scale"yuliaUU
Where is the ggmap call?Paulo E. Cardoso

1 Answers

2
votes
library(ggmap)
library(ggplot2)


lis <- get_map("Lisbon,Portugal", zoom=12)

p <- ggmap(lis)

d <- data.frame(lon=c(-9.20, -9.20, -9.12),
                lat=c(38.65, 38.80, 38.75),
                loc = c('p1', 'p2', 'p3'))

p + geom_point(data=d, aes(x=lon, y=lat),
               colour = 'red', size = 8, alpha = .6) +
  geom_text(aes(label=loc), data=d, hjust=-1,
            fontface = 'bold')

enter image description here

Not sure if this is close to your needs. You should provide further details on how your data relates to ggmap (providing coordinates maybe?)