0

我遇到的问题是,每次我尝试将我的点绘制到地图上时,它似乎都会删除它们。

#getmap
 library(ggplot2)
 library(ggmap)
 testmap <- get_googlemap(c(lon=135,lat=-32) ,zoom=6, 
 xlim=c(127,142), ylim=c(-23,-34))
 save(testmap, file="test.rda")

#Load file
load(file="test.rda")

#plot
plotvar <- c("V37","V39")
plotdata <- WellDownload[plotvar]
 #plotting
ggmap(testmap) + geom_point(aes_string(x=plotdata$V37, y=plotdata$V39), 
data=plotdata, colour="red", size=3)

Removed 10001 rows containing missing values (geom_point).

是我得到的错误,我的数据库确实缺少值,但我不明白为什么要删除值。

我的目标是在地图上绘制点,然后根据坐标将数据外推到地图上。我只是想找出为什么会出现这些错误,我有数据库的 txt 文件,但不知道如何上传。

编辑希望这应该工作https://www.dropbox.com/s/4rv52deuehyfn9l/WellDownload.txt这是文件

编辑:我只是尝试了另一种访问数据的方法,它不再删除行,而是说"Discrete value supplied to continuous scale".

#load file
 load(file="e:/CameronFurness/xml_data/test.rda")
#data
 mydata <-data.frame(x<-newdata[,"V37"],y<-newdata[,"V39"],#lon= V37, lat=V39, 
   col = NA_real_)
 #plot
 ggmap(testmap) + geom_point(aes(x, y), data=mydata, size=3, alpha=0.5, colour="red")

newdata是我用列V37V39. 我正在使用的坐标在文件中,它们是decimal_longneg_decimal_lat.

4

1 回答 1

1

因此,您的数据集有一些不错的列名,例如“decimal_long”和“decimal_lat”。当您拥有这些时,您希望将它们用作列名,而不是像“V37”和“V39”这样的默认名称。

为了获得这些默认名称,我猜你在没有标题的情况下读取数据,而实际上它有一个:

plotdata <- read.table("WellDownload.txt", sep = "\t", header = T)

## To keep it simple, I'm going to keep only those two columns,
## and only the first 100 rows.
plotdata <- plotdata[1:100, c("neg_decimal_lat", "decimal_long")]

# Then the rest works just fine.
#getmap
library(ggplot2)
library(ggmap)
testmap <- get_googlemap(c(lon=135,lat=-32) ,zoom=6, 
                         xlim=c(127,142), ylim=c(-23,-34))

#plotting
ggmap(testmap) + geom_point(aes(x= decimal_long, y=neg_decimal_lat), 
                            data=plotdata, colour="red", size=3)

它有效!

在此处输入图像描述

您的数据中可能存在其他问题。当我阅读它时,我收到了警告:

Warning messages:
1: In scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  :
  EOF within quoted string
2: In scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  :
  number of items read is not a multiple of the number of columns

听起来数据文件有不匹配的引号。当我试图查看文件的尾部时,我的 R 会话崩溃了。我建议在电子表格中打开它并在将其放入 R 之前对其进行一些清理。

于 2013-11-12T23:57:28.117 回答