Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I plot a single point on a world map, using ggplot2?

Tags:

r

ggplot2

on a world map, how do I plot a single point?

all_states <- map_data("usa")
p <- p + geom_polygon( data=all_states, aes(x=long, y=lat, group = group, legend = FALSE))
p

Also, is it possible to remove the grid and the lat long values form the map?


1 Answers

library(maps)
library(ggplot2)
world<-map_data('world')
sf<-data.frame(long=-122.26,lat=37.47)
p <- ggplot(legend=FALSE) +
geom_polygon( data=world, aes(x=long, y=lat,group=group)) +
opts(panel.background = theme_blank()) +
opts(panel.grid.major = theme_blank()) +
opts(panel.grid.minor = theme_blank()) +
opts(axis.text.x = theme_blank(),axis.text.y = theme_blank()) +
opts(axis.ticks = theme_blank()) +
xlab("") + ylab("")
# add a single point

p <- p + geom_point(data=sf,aes(long,lat),colour="green",size=4)
p

Note: Since version 0.9.2 opts has been replaced by theme. So for example, opts(panel.background = theme_blank()) would become theme(panel.background = element_blank()).

like image 157
Maiasaura Avatar answered Aug 27 '26 22:08

Maiasaura