2

I'm trying to create a figure in R that has a base worldmap with locations overlaid on top as points. I'd also like to specify the size and color of the points with additional data from my dataframe. Here is my code as it stands:

#reading in data
world <-map_data("world")
data <-read.csv("map_data.csv", header=TRUE)

#creating base worldmap
worldbase <- ggplot()+
  geom_polygon(data=world, aes(x=long, y=lat, group=group), fill=NA, color="black") + 
  coord_fixed(1.3)

#overlaying points on top of base map
worldbase +
  geom_point(data=data, mapping=aes(x=Long_DD, y=Lat_DD, size=total_bases, color=factor(seq_type))) #These are all columns in my dataframe containing longitude, latitude, continuous information (total_bases) and categorical information (seq_type).

Currently, I'm getting the error message

"Error: Discrete value supplied to continuous scale"

I know this has to do with my x and y specifications, but how else would I plot the lat and long values from my dataframe?

Vinícius Félix
  • 8,448
  • 6
  • 16
  • 32
  • 2
    Welcome to SO! Please add some (also fake) data that makes your code working also for people that cannot have them; if you are using some external packages (like ggplot2), it should be added to make your code reproducible. It's going to be easier to help you! – s__ Nov 10 '20 at 18:52
  • Without a look at your data we can only guess. One reason could be that your Long_DD or Lat_DD variables aren't numerics but e.g. characters instead. You could check the datatypes via e.g. `str(data)`. – stefan Nov 10 '20 at 19:00
  • Thank you both! Using as.numeric for lat and long values seemed to fix the issue--much obliged! – Maggie Weng Nov 10 '20 at 20:00

0 Answers0