# 生成数据
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[1, 4:7] <- d[1, 4:7] * 3
head(d)
p <- ggplot() + geom_scatterpie(aes(x=long, y=lat, group=region), data=d,
cols=LETTERS[1:4]) + coord_equal()
自定义样式
theme_half<- function(){
theme(
panel.background = element_rect(fill="transparent"),
panel.grid = element_line(color = "#cccccc"),
legend.key = element_blank(),
axis.line = element_line(colour = "black"),
)
}
p + theme_half()
p + theme_classic()
参考资料
https://cran.r-project.org/web/packages/scatterpie/vignettes/scatterpie.html