作者rleaner (rleaner)
看板R_Language
标题[问题] geom_point读值出错
时间Fri Feb 24 19:20:34 2017
[目的]================================================
已把各点的座标资料转为如下矩阵:
pm2.5_anime:
[,1] [,2] [,3]
[1,] "74DA3895C4C8" "74DA3895C2A6" "74DA3895C374"
[2,] "24.215748" "24.198088" "24.196424"
[3,] "120.526291" "120.523407" "120.547585"
[4,] "49.3" "57.3" "57.2"
[5,] "49.7" "56.3636363636364" "58.4"
[6,] "50.3" "58.7" "57.8"
pm2.5_anime[1,] -> 是各座标sensor的id
pm2.5_anime[2,]、pm2.5_anime[3,] ->经纬度
pm2.5_anime[4~6,] 是该座标上不同时段的pm2.5的值
希望能把pm2.5的值以geom_point显示在
ggmap上,并用图层叠加的方法做出动态地图的效
但geom_point读值时出错QAQ
[程式]================================================
library(ggplot2)
library(ggmap)
library(mapproj)
point_f <- data.frame(lng=pm2.5_anime[3,], lat=pm2.5_anime[2,] ,
siz=pm2.5_anime[4,] )
map <- get_map(location = c(lng=120.601,lat=24.179),
zoom = 10, language = "zh-TW", maptype = "roadmap" ,scale = 1)
ggmap(map)+
geom_point(data= point_f , aes( x =lng , y=lat),size= 10)
[问题!!!]================================================
在geom_point(data= point_f , aes( x =lng , y=lat),size= 10)
这行出问题
错误息讯是:
Error: Discrete value supplied to continuous scale
google方法还是没用,
求大大们帮帮忙
QAQ
还有那段错误倒底是什麽意思
>"<
[环境]================================================
R version 3.3.2 (2016-10-31
win7
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 140.128.101.15
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/R_Language/M.1487935237.A.C32.html
1F:→ celestialgod: 你是字串要画图?要记得转成numeric 02/24 19:23
嗯嗯~我是要画在ggmap上
我刚有试每个值要丢入pm2.5_anime时,用as.numeric去转,如:
pm2.5_anime <- matrix(NA,ncol= all_sensor,nrow = 9)
for(i in 1:all_sensor){#make anime matrix
pm2.5_anime[1,i] <- toString( MS_t$device_id[i+1])
pm2.5_anime[2,i] <- as.numeric(MS_t$lat[i+1])
pm2.5_anime[3,i] <- as.numeric(MS_t$lng[i+1])
}
但还是失败
XD
※ 编辑: rleaner (140.128.101.15), 02/24/2017 19:32:17
2F:→ celestialgod: = =" 这样当然还是错啊 02/24 20:22
3F:→ celestialgod: 你矩阵一次只能存一种类型的变数... 02/24 20:22
4F:→ celestialgod: 第一个column存string, 二三存numeric 02/24 20:22
5F:→ celestialgod: 按照r逻辑整个矩阵就是string了 02/24 20:22
6F:→ celestialgod: 你需要的是先去把 R翻转教室玩过一次 02/24 20:23
7F:→ celestialgod: 不是在这问题怎麽解... 基本概念都不通了 怎麽教... 02/24 20:23
嗯嗯嗯~
感谢拨冗指教
我会先回去补基础
@@
※ 编辑: rleaner (140.128.101.15), 02/24/2017 20:43:23