0

I am trying to represent dots/bubble corresponding to cities that increase size proportional to population.

despite several attempts, I get always the same error ("Discrete value supplied to continuous scale"), even though my variable is numeric.

Example Data used can be found here

https://github.com/Lulliter/r-ggplot-points-question

  1. Brazil_bound_sf = boundary
  2. Brazil_cit_longlat = list of cities with Population # over few years

Plot does not Work

ggplot() + 
  geom_sf (data = Brazil_bound_sf, 
         aes(fill = NULL), alpha = .1,colour = "darkgrey",size = 0.3) +
  geom_point(data = Brazil_cit_longlat, aes( x = lon, y = lat, size = 
           "2016"), fill = "red", color = "grey", alpha = .2) + 
  scale_size_continuous()  +

  coord_sf(crs = st_crs(Brazil_bound_sf), datum = NA) + 
  theme_void() 

# Error: Discrete value supplied to continuous scale

Thanks!

Lulliter
  • 87
  • 1
  • 7
  • 3
    you supplied `size = "2016"`. `"2016"` is not a numeric value. Are you trying to literally map `"2016"` to size or is `2016` the name of one of your columns? – Jack Brookes Oct 24 '18 at 21:26
  • Btw, you might prefer `scale_size_area` if you want size proportional to population, instead of radius. – Jon Spring Oct 24 '18 at 21:27
  • Welcome to SO! Please, it's [recommended](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) to `dput()` your data, and post the result editing your question. If they are too much, you can `dput(head(,20))` your data ( for example, `dput(head(Brazil_bound_sf,20))` and `dput(head(Brazil_cit_longlat,20))`). – s__ Oct 24 '18 at 21:28

1 Answers1

1

This worked for me (I simply replaced "2016" with 2016. This way you are referring to the column in the data frame and not to the string "2016":

ggplot() + 
  geom_sf (data = x, 
           aes(fill = NULL), alpha = .1,colour = "darkgrey",size = 0.3) +
  geom_point(data = y, aes( x = lon, y = lat, size = 
                                               `2016`), fill = "red", color = "grey", alpha = .2) + 
  scale_size_continuous()  + 
  sf::plot_sf(crs = st_crs(x), datum = NA)
Henry Cyranka
  • 2,970
  • 1
  • 16
  • 21