Reputation: 132
I am struggling to plot some lines using ggplot in R. I need to connect each pairs (grouped by INDEX). The data I am using is:
INDEX | LATITUDE | LONGITUDE | VALUE
1 53,071118 -6,063786 40.3
1 53,076478 -6,067592 40.3
2 53,071118 -6,063786 60.7
2 53,099204 -6,067235 60.7
And the code:
require(ggmap);
require(ggplot2);
options(warn=-1)
mydata = read.delim2("mydata.csv", TRUE, "\t")
df=as.data.frame(mydata)
City="Dublin, Ireland"
baseMap = get_map(location = City, zoom = 11, maptype = "terrain")
map <- ggmap(baseMap) +
geom_path(aes(x=LONGITUDE, y=LATITUDE, group=INDEX), data=df, alpha=0.2)
map
On the last two lines the error is "Error: Discrete value supplied to continuous scale". How can I overcome that?
Edit: I inserted
df$LATITUDE=as.numeric(as.character(df$LATITUDE))
df$LONGITUDE=as.numeric(as.character(df$LONGITUDE))
df$INDEX=as.numeric(as.character(df$INDEX))
and it started working. Bear in mind that the coordinates had to be with dots, not commas.
Upvotes: 2
Views: 1831
Reputation: 132
I just needed adding
df$LATITUDE=as.numeric(as.character(df$LATITUDE))
df$LONGITUDE=as.numeric(as.character(df$LONGITUDE))
df$INDEX=as.numeric(as.character(df$INDEX))
and replacing ',' in the data with '.'
Upvotes: 1