I'm trying to plot a series of points over a map.
I have two data sets nt and patients - nt is a SpatialPolygonsDataFrame and patients is a data.frame
I can plot nt but line
points(patients$long, patients$lat, col ="green", cex=.6)
has no effect
Note that some rows in patients are outside nt I can plot patients on its own.
A bit of code - I hope it formats properly @R.S.
library(ggplot2)
plot.new()
map <- ggplot() +
geom_path(data = nt,
aes(x = long, y = lat, group = group),
color = "gray", size = .2
)
map <- map + theme_bw()
print( map)
points(nt_pats$long, nt_pats$lat, col ="green", cex=.6)
Initially I want to plot patients over nt Later I want to indicate number of patients and their home addresses.
Thanks in advance Mick
Sample data
head(patients) locality long lat No.patients State.Code Postcode State.Abbr 1 BLACKMANS BAY 147.322 -42.997 1 6 7052 TAS 2 SOUTH HOBART 147.310 -42.896 4 6 7004 TAS 3 BELLERIVE 147.371 -42.873 2 6 7018 TAS 4 LENAH VALLEY 147.287 -42.872 1 6 7008 TAS 5 NEW NORFOLK 147.059 -42.781 1 6 7140 TAS 6 KEMPTON 147.200 -42.532 1 6 7030 TAS
> head(nt,1)
An object of class "SpatialPolygonsDataFrame"
Slot "data":
STATE_CODE CD_CODE06 SLA_CODE06 SLA_NAME06 LGA_CODE06 LGA_NAME06
0 7 7010101 705051004 Alawa 71000 Darwin (C)
Slot "polygons":
[[1]]
An object of class "Polygons"
Slot "Polygons":
[[1]]
An object of class "Polygon"
Slot "labpt":
[1] 130.87870 -12.37927
Slot "area":
[1] 2.317102e-05
Slot "hole":
[1] FALSE
Slot "ringDir":
[1] 1
Slot "coords":
[,1] [,2]
[1,] 130.8756 -12.38281
[2,] 130.8753 -12.38126
[3,] 130.8761 -12.38112
[4,] 130.8775 -12.38087
...
Slot "plotOrder":
[1] 1
Slot "labpt":
[1] 130.87870 -12.37927
Slot "ID":
[1] "0"
Slot "area":
[1] 2.317102e-05
Slot "plotOrder":
[1] 1
Slot "bbox":
min max
x 130.87529 130.88214
y -12.38281 -12.37602
Slot "proj4string":
CRS arguments:
+proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs