简体   繁体   English

ggmap没有从数据框中绘制地图上的所有点

[英]ggmap not plotting all points on map from dataframe

The problem I am having is that every time I try to plot my points onto a map it seems to remove them. 我遇到的问题是,每次尝试将点绘制到地图上时,似乎都将其删除。

#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).

is the error I get, my database does have missing values but I don't understand why values are being removed. 是我得到的错误,我的数据库确实缺少值,但是我不明白为什么要删除值。

What I am aiming to do is to plot points on a map then later do an extrapolation of the data onto the maps based on the coords. 我的目的是在地图上绘制点,然后根据坐标将数据外推到地图上。 I just wanted to find out why I was getting these errors, I have the txt file for the database but am not sure how to upload it. 我只是想找出为什么会出现这些错误,我有数据库的txt文件,但不确定如何上传它。

EDIT hopefully this should work https://www.dropbox.com/s/4rv52deuehyfn9l/WellDownload.txt here is the file 编辑希望这应该可以工作https://www.dropbox.com/s/4rv52deuehyfn9l/WellDownload.txt这是文件

Edit: I just tried a different method of accessing the data and its not removing rows anymore but says "Discrete value supplied to continuous scale" . 编辑:我只是尝试了一种不同的方法来访问数据,它不再删除行,而是说"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 is a data frame I made with columns V37 and V39 . newdata是我使用列V37V39构成的数据帧。 The coords I am using are in the file, they are decimal_long and neg_decimal_lat . 我使用的是COORDS文件中,他们decimal_longneg_decimal_lat

So, your data set has some nice column names, like "decimal_long" and "decimal_lat". 因此,您的数据集具有一些不错的列名,例如“ decimal_long”和“ decimal_lat”。 When you have those, you want to use those as column names, not the default names like "V37" and "V39". 当拥有这些名称时,您想将它们用作列名,而不要使用默认名称,例如“ V37”和“ V39”。

To get those default names, I'm guessing you read your data in without a header, when in fact it has one: 为了获得这些默认名称,我猜想您读入的数据没有标题,而实际上却有一个:

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)

And it works! 而且有效!

在此处输入图片说明

There may be other problems in your data. 您的数据中可能还存在其他问题。 When I read it in, I got warnings: 当我阅读它时,我得到警告:

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

It sounds like the data file has unmatched quotation marks. 听起来数据文件具有不匹配的引号。 When I tried to look at the tail of the file, my R session crashed. 当我尝试查看文件的末尾时,我的R会话崩溃了。 I'd suggest opening it in a spreadsheet and cleaning it a little before putting it into R. 我建议在电子表格中打开它并清洗一点,然后再放入R中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM