문제

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.

EDIT hopefully this should work https://www.dropbox.com/s/4rv52deuehyfn9l/WellDownload.txt here is the file

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".

#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. The coords I am using are in the file, they are decimal_long and neg_decimal_lat.

도움이 되었습니까?

해결책

So, your data set has some nice column names, like "decimal_long" and "decimal_lat". When you have those, you want to use those as column names, not the default names like "V37" and "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!

enter image description here

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. I'd suggest opening it in a spreadsheet and cleaning it a little before putting it into R.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top