YuLab-SMU / scatterpie

:art: scatter pie plot
https://cran.r-project.org/package=scatterpie
60 stars 16 forks source link

Error "Discrete value supplied to continuous scale" shows up when aes(fill) is set #2

Closed linx0830 closed 7 years ago

linx0830 commented 7 years ago

In the following example, if "fill" geom_map(aes()) is set, the error "Discrete value supplied to continuous scale" shows up; however, if "fill" is not in aes(), it is fine.

set.seed(123)
long <- rnorm(50, sd=100)
lat <- rnorm(50, sd=50)
d <- data.frame(long=long, lat=lat)
d <- with(d, d[abs(long) < 150 & abs(lat) < 70,])
n <- nrow(d)
d$region <- factor(1:n)
d$A <- abs(rnorm(n, sd=1))
d$B <- abs(rnorm(n, sd=2))
d$C <- abs(rnorm(n, sd=3))
d$D <- abs(rnorm(n, sd=4))
d$radius <- 6 * abs(rnorm(n))

world <- map_data('world')
p <- ggplot(world, aes(long, lat)) +
  geom_map(map=world, aes(map_id=region, fill=long), color="black") + # error
# geom_map(map=world, aes(map_id=region), fill=NA, color="black") + # fine
  coord_quickmap()

p + geom_scatterpie(aes(x=long, y=lat, group=region, r=radius),
                    data=d, cols=LETTERS[1:4], color=NA, alpha=.8) +
  geom_scatterpie_legend(d$radius, x=-160, y=-55)
GuangchuangYu commented 7 years ago

This is an issue of ggplot2 which wont allow mapping 2 both discrete and continuous variable to aes(fill).

geom_scatterpie will map aes(fill) to fill the pies (of course discrete values), and it will conflict with your aes(fill=long).