Error: Discrete value supplied to continuous scale in ggplot + geom_scatterpie

124 views Asked by At

I'm trying to do a map with ggplot and geom_scatterpie function but I'm keep receiving this error: "Error: Discrete value supplied to continuous scale"

the code is the following:

ggplot() +
  geom_tile(data = my_raster, aes(x = x, y = y, fill = values)) +
  scale_fill_gradientn(colours = c("white", "white", "white", "white", "grey", "white", "white"), na.value = "white", guide="none")  +
  geom_sf(data = europe_cropped, size = 0.1, color = "black", fill = "white", alpha = 0.4) +
  geom_scatterpie(aes(x = long, y = lat, r = 2), 
                  cols = colnames(my_table[2:5], color = "black",
                  data = my_table)  +
  ylab("") +
  xlab("") +
  coord_sf() +
  theme_few()

I've tried to run it without the geom_tile and scale_fill lines and it works but I need that raster as base of the map. What could be the problem the gives the error?

edit:

head(my_raster)

x y focal_max
-9.979089 64.98143 200
-9.965076 64.98143 200
-9.951063 64.98143 200
-9.937050 64.98143 200
-9.923037 64.98143 200
-9.909024 64.98143 200

head(my_table)

site group1 group2 group3 group4 lat long
site1 0.317 0 0.0448 0.280 47.7 5.08
site2 0.370 0 0.0359 0.319 47.8 5.07
site3 0.344 0 0.0269 0.233 47.8 5.12
site4 0.317 0 0.00896 0.342 47.8 5.06
site5 0.291 0 0.0538 0.373 47.8 5.04
site6 0.476 0 0.0179 0.490 47.7 5.12
0

There are 0 answers