I have a map of the USA and a list of long, lat that I want to plot. Once I get this working, I also want to switch over to the "world" map. The map is generated, but no points appear on the map. The first line of the TSV file contains this header:
LONG{tab}LATR appears to be reading in the 'traffic' table OK. What am I doing wrong?
library("maps") traffic = read.table("C:/temp/traffic_10.40.tsv", header=T, sep="\t") png(filename="C:/temp/usa.png", width=850, height=600, bg="white") map('state', plot = TRUE, fill = FALSE, col = palette()) title("Destinations") points(x=traffic$LONG,y=traffic$LAT,col='red',cex=0.75) dev.off()
EDIT
> dput(traffic) structure(list(LONG = c(47.6218, 32.7942, 34.1121, 40.0068, 47.6218, 33.9553, 33.7629, 40.0068, 39.05, 38.1075, 33.7629, 32.769, 37.3857, 29.4576, 34.1674, 38.8147, 32.7942, 31.1429, 40.3254, 30.3059, 38.2248, 47.6218, 33.9553, 38.1075, 27.1943, 29.4576, 30.5175, 38.5668, 42.6657, 40.2982, 32.7539, 40.6698, 47.6742, 32.7942, 47.6218, 35.8219), LAT = c(-122.35, -96.7653, -118.411, -75.1347, -122.35, -83.3937, -84.4226, -75.1347, -77.4833, -122.264, -84.4226, -96.5998, -122.026, -98.5054, -84.8014, -77.0647, -96.7653, -81.471, -78.9195, -97.7505, -85.7412, -122.35, -83.3937, -122.264, -80.2432, -98.5054, -97.6721, -121.467, -73.799, -111.698, -97.3363, -73.9438, -122.115, -96.7653, -122.35, -78.6588)), .Names = c("LONG", "LAT" ), class = "data.frame", row.names = c(NA, -36L))
Also, I am a R newbie and have tried finding this on google with limited success because I am not sure what to search for exactly.
The problem is in your data set rather than your later code.
The first point has one co-ordinate 47.6218
and the other -122.35
. Latitudes cannot be outside the range [-90,90]
degrees so the longitude must be -122.35
and latitude 47.6218
, the opposite of your data set. This is slightly north of the Seattle Space needle
x
(horizontal) is traditionally longitude or easting; y
(vertical) is traditionally latitude or northing
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With