0

I am trying to plot a world map of specific lake sites (lat and long) and the further differentiate the points according to the two variables (Model for color and Size for Total), aiming at the end to have a sort of bubble plot over a world map.

That's how my data (WD) looks like (data.frame)

WD <- read.csv(file.choose(), header = TRUE)
head(WD)

    Country                Lake        Lat       Long Model Total
1       USA         Annie, lake  27.994549 -81.604644    PB     0
2       USA         Annie, lake  27.994549 -81.604644    DD     1
3 Australia   Baroon, reservoir -26.706919 152.870361    PB     0
4 Australia   Baroon, reservoir -26.706919 152.870361    DD     2
5   England Bassenthwaite, lake    54.6525  -3.225833    PB     3
6   England Bassenthwaite, lake    54.6525  -3.225833    DD     0

I've downloaded the world map using

library("ggmap")
library(maptools)
library(maps)
mapWorld <- borders("world", colour="gray50", fill="white")

plotting the map without points is ok

mp <- ggplot() + mapWorld

enter image description here

then I try to add the points by

mp <- mp+ geom_point(data=WD, aes(x=Long, y=Lat) ,color=WD$Model,alpha=0.5, size=WD$Total)

but when I try to plot mp the below error appears and I don't know how to figure this out

Error: Discrete value supplied to continuous scale
jay.sf
  • 60,139
  • 8
  • 53
  • 110
  • 1
    Chech the data type of `Lon` and `Lat` they may be factors. If this is not the case please provide data to reproduce the example. https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Sada93 Feb 19 '19 at 05:49

2 Answers2

2

Without having your data there were a few things that stuck out to me. In your geom_point layer I think your size and color should be inside the aes() like so:

mp + geom_point(data = WD, aes(x = Long, y = Lat, color = Model, size = Total), alpha = 0.5)

Those may not be the only problems, and it is usually a good idea to start with the basics of a ggplot layer and see if that will work, and then get fancy with the color and size. That can help nail down where the problem is. So in your case, just try and see if it will plot with the Lat and Long first.

I would also suggest checking that you don't have any NA's in your data and that the dataframe vectors are the appropriate class for each spot you are trying to plug it in at (factor, character, numeric, etc...). Each of those problems have wasted me a great deal of time at one point or another...

Good luck!

cdtip
  • 153
  • 7
0

thanks for the tips. I found out there one of the variables was a factor, but even after correcting this the problem persisted. So I restarted R several times and it magically worked