0

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.

hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
Cam.f
  • 105
  • 2
  • 9
  • I can sort of duplicate your error by creating some fake data which tries to plot results that are outside the plotting area. Of course it's impossible to directly address your real question without your data, but I'd try expanding your xlim and ylim and see if that helps. – Chase Nov 12 '13 at 04:44
  • Hi cheers for the response, I have tried to increase the xlim,ylim but I think its got something to do with the dataset itself even though I tried to ignore or fill missing values – Cam.f Nov 12 '13 at 23:09
  • Instead of posting 55 columns of data, how about you post just the two columns you are using? You could also probably post just 10 rows. Then you can use `dput` to post the data directly into the question and everyone is happy. – Gregor Thomas Nov 12 '13 at 23:45
  • You also don't need to have us create a map, save it, and load it. You could just create it. – Gregor Thomas Nov 12 '13 at 23:46
  • Moreover, if the problem is in your data, then *it matters how you load your data*. Showing that you used `load()` on a, `.rda` file we don't have, we can't help you because we don't have the `.rda` file. Giving us a `.txt` file but not showing how you read it into R is basically the same problem, you only give us half the picture. – Gregor Thomas Nov 13 '13 at 00:12

1 Answers1

1

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.

Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
  • Thank you so much I've been stuck on this for a few days and its been quite frustrating thanks again I'll go clean out the txt file now, I thought something was wrong with it – Cam.f Nov 13 '13 at 00:35