I want to plot pie charts using geom_scatterpie
on top of a geom_tile plot. However, I am getting an error:
Error: Discrete value supplied to continuous scale
Here's the simple code that I cannot get to work:
library(ggplot2)
library(scatterpie)
nasafile <- "http://eosweb.larc.nasa.gov/sse/global/text/global_radiation"
nasa <- read.table(file=nasafile, skip=13, header=TRUE)
p <- ggplot(aes(y = Lat , x = Lon), data = nasa )+
geom_tile(aes(fill=Ann)) +
scale_fill_gradientn(colours=brewer.pal('YlOrRd', n=9)) +
theme_bw() +
coord_equal()
plot(p)
This works, but if I add the geom_scatterpie
on top of that:
First the data for the pie charts to plot:
d <- data.frame(x=rnorm(5), y=rnorm(5))
d$A <- abs(rnorm(5, sd=1))
d$B <- abs(rnorm(5, sd=2))
d$C <- abs(rnorm(5, sd=3))
But I get the error when I do this:
p + geom_scatterpie(aes(x=x, y=y), data=d, cols=c("A", "B", "C")) + coord_fixed()