- a little bit about colours and overplotting
- using data from different data frames with different layers of a plot
Here the final map:
The darker circles indicate that more people came from there. This is the "alpha" argument of the geom_point() function.
As a scientist, I like the labels on the longitude and latitude labels on the axis.
Here is the script including some of the pictures along the way:
# draw a map of the UK with R.
library(maps) # Provides functions that let us plot the maps
library(mapdata) # Contains the hi-resolution points that mark out the countries.
# use the map() function which comes from the maps package
c('UK', 'Ireland', 'Isle of Man','Isle of Wight', 'Wales:Anglesey'))
# very small map
# make it larger by limiting the x and y axis which corresponds to
# longitude and latitude
# import delagate info
data <- read.csv("http://science2therapy.com/data/locations.csv")
# we can also do this in ggplot probably better...
# use map_data()function to create a data.frame containing the map of the UK
uk<-map_data("worldHires", region = "UK")
# create the object m with the map in it.
# we can make the map different colours
# see here for more about colours in R
m <- ggplot() +
aes(x=long, y=lat, group=group),
fill="gray88") + # see link for a list of R colours
scale_x_continuous(limits = c(-10,3)) +
# add the points on the plot telling us where the longitude and latitude of various places
# note the data is coming from a different data.frame to the map
m <- m + geom_point(data=data,
alpha=0.5, colour="red", size = 5)
# change the theme to make the map nicer
m <- m + theme_bw()
# add a title
m + ggtitle("Where the R for Biochemists delagates came from...")
END OF SCRIPT
Sources of advice and help: