楼主: xingzhaoh
14586 13

[作图问题求助] 如何在中国地图的省份上绘制柱状图 [推广有奖]

11
ryusukekenji 发表于 2013-9-6 04:40:57
xingzhaoh 发表于 2013-9-5 16:11
可以分享一下codes吗?不胜感激
  1. library(ggsubplot)
  2. library(ggplot2)
  3. library(maps)
  4. library(plyr)

  5. #Get world map info
  6. world_map <- map_data("world")

  7. #Create a base plot
  8. p <- ggplot()  + geom_polygon(data=world_map,aes(x=long, y=lat,group=group))

  9. # Calculate the mean longitude and latitude per region, these will be the coördinates where the plots will be placed, so you can tweak them where needed.
  10. # Create simulation data of the age distribution per region and merge the two.

  11. centres <- ddply(world_map,.(region),summarize,long=mean(long),lat=mean(lat))
  12. mycat <- cut(runif(1000), c(0, 0.1, 0.3, 0.6, 1), labels=FALSE)
  13. mycat <- as.factor(mycat)
  14. age <- factor(mycat,labels=c("<15","15-30","20-60",">60"))
  15. simdat <- merge(centres ,age)
  16. colnames(simdat) <- c( "region","long","lat","Age" )

  17. # Select the countries where you want a subplot for and plot
  18. simdat2 <- subset(simdat, region %in% c("USA","China","USSR","Brazil", "Australia"))
  19. (testplot <- p+geom_subplot2d(aes(long, lat, subplot = geom_bar(aes(Age, ..count.., fill = Age))), bins = c(15,12), ref = NULL, width = rel(0.8), data = simdat2))
复制代码
ggplot2, ggsubplot, plotrix 也不错... 顺道分享一下没有代码的分享。
http://stackoverflow.com/questio ... a-map-using-ggplot2
已有 1 人评分学术水平 热心指数 收起 理由
耕耘使者 + 1 + 1 热心帮助其他会员

总评分: 学术水平 + 1  热心指数 + 1   查看全部评分

12
BDP 发表于 2017-9-27 19:25:38
我称这种图表为地图上的迷你图,哈哈,之前做过一些~ 应该是你想要的
上海地图+条形图
北京地图+柱状图

可以参考一下这个:数据地图+迷你图(http://t.cn/R09jCeu)



13
BDP 发表于 2017-10-19 21:27:35
其实不太难,就是统计地图。

地图+条形图.png (1.05 MB)

地图+条形图.png

gis.png (742.08 KB)

gis.png

14
数据运营 在职认证  发表于 2017-11-20 15:13:26
地图上实现柱状图、条形图和饼图,在可视化工具BDP中都是可以通过拖拽实现的,不需要代码,不会的可以交流~

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-30 23:39