提供给连续标度R的离散值

时间:2015-04-15 17:35:58

标签: r dictionary ggplot2 latitude-longitude ggmap

我知道这个问题在这里被多次询问过。但是,即使我认为我的代码足够好,我似乎也得到了相同的错误消息“提供给连续比例的离散值”。我不明白原因。我从csv文件导入经度和纬度值并构造数据框。但是我无法在地图上绘制所有我得到的点是欧洲地图而没有积分。

library(ggmap)
library(ggplot2)

g <- data.frame(lon=longitude, lat=latitude)

Europe <- get_map(location="Europe", zoom=3)

map <- ggmap(Europe)
map + geom_point(data=g, aes(x=longitude, y=latitude), color="blue", size=3)

示例数据:

latitude  
28.42222222
29.76328
18.079733
19.2539846
27.66955857
23.1525609
12.958251
16.3577847
28.5912216
19.254039
25.1450198
23.15276151
19.2539879
19.253986
28.6598034
23.1530814

longitude
100.7680556
95.36327
73.418583
73.1403781
84.42628936
79.9333897
77.5543671
80.8691776
77.1237985
73.1403918
85.2033903
79.9332153
73.140418
73.1404192
77.1903172
79.9329372

EDITED DPUT

> dput(g)
structure(list(lon = structure(c(1L, 16L, 6L, 2L, 14L, 12L, 9L, 
13L, 7L, 3L, 15L, 11L, 4L, 5L, 8L, 10L), .Label = c("100.7680556", 
"73.1403781", "73.1403918", "73.140418", "73.1404192", "73.418583", 
"77.1237985", "77.1903172", "77.5543671", "79.9329372", "79.9332153", 
"79.9333897", "80.8691776", "84.42628936", "85.2033903", "95.36327"
), class = "factor"), lat = structure(c(13L, 16L, 3L, 4L, 12L, 
8L, 1L, 2L, 14L, 7L, 11L, 9L, 6L, 5L, 15L, 10L), .Label = c("12.958251", 
"16.3577847", "18.079733", "19.2539846", "19.253986", "19.2539879", 
"19.254039", "23.1525609", "23.15276151", "23.1530814", "25.1450198", 
"27.66955857", "28.42222222", "28.5912216", "28.6598034", "29.76328"
), class = "factor")), .Names = c("lon", "lat"), row.names = c(NA, 
-16L), class = "data.frame")

2 个答案:

答案 0 :(得分:0)

你的g使用lat和long作为因素,而不是数字。尝试将其转换为数字:

g$lon<-as.numeric(as.character(g$lon))
g$lat<-as.numeric(as.character(g$lat))

答案 1 :(得分:0)

将lon和lat转换为数字后,如user2034412建议的那样,这就是结果。我感谢同一个人对as.character的评论。

g$lon <- as.numeric(as.character(g$lon))
g$lat <- as.numeric(as.character(g$lat))

Europe <- get_map(location="Europe", zoom=3)

map <- ggmap(Europe) +
 geom_point(data=g, aes(x=lon, y=lat), color="blue", size=3)
  geom_point(data=g, aes(x=lon, y=lat))

地图 enter image description here

相关问题