2

enter image description here

I've tried to plot a map of magnitude earthquakes in Colombia with ggplot. After many efforts, I got it. But, I need to focus in specially area where the data of magnitudes is (4, 4.1, 4.2, 4.3, 4.4, 4.5, 4.6, 4.7, 4.8, 4.9, 5). When I use the same script for this data, I get this:

"Error: Discrete value supplied to continuous scale".

I've used many solutions in blogs but it does not work.

This is my first map and the script

santos <- readOGR("Departamentos_WGS84.shp","Departamentos_WGS84")
map <- fortify(santos)
datos=read.table("coord.txt",header=T,dec=",",sep=";")
myData = data.frame(datos)
gg <- ggplot()
gg <- gg + geom_map(data=map, map=map,
 aes(x=long, y=lat, map_id=id, group=group),
 fill="#fffcfc", color="#0e0e0e", size=0.15) + 
 geom_point(data=myData, 
 aes(x=long, y=lat, size=Magnitud), color = "red",shape = 21) +
 scale_size(range = c(0, 8)) + 
 coord_map() + 
 theme_bw() + 
 labs(x=NULL, y=NULL) + 
 theme(panel.grid=element_blank()) + 
 theme(panel.border=element_rect())
 gg
Michal Zimmermann
4,2621 gold badge25 silver badges40 bronze badges
asked Jan 14, 2016 at 4:49
7
  • I do not understand your question. My data are coordinates (longitude and latitutde) associated with a magnitude. I hope this answers your question. Commented Jan 14, 2016 at 16:23
  • what is the output of this command class(myData$Magnitud)? factor or numeric (this could be the source of your error) Commented Jan 14, 2016 at 19:30
  • I guess myData$long and/or myData$lat are character values ("discrete"), because the read.table does not work as expected. And that does not match with map$long, which is numeric. Maybe you can add the output of str(map) and str(myData). Commented Jan 14, 2016 at 19:32
  • Excuse me! With class(myData$Magnitud), I got "factor". Commented Jan 14, 2016 at 20:12
  • 1
    this should be numeric Commented Jan 14, 2016 at 20:38

1 Answer 1

1

I solved this problem with these instructions:

myData$longitude = as.numeric(as.character(myData$longitude))
myData$Magnitude = as.numeric(as.character(myData$Magnitude))
myData$latitude = as.numeric(as.character(myData$latitude))
Aaron
52k30 gold badges161 silver badges327 bronze badges
answered Jan 20, 2016 at 1:53

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.