r - 谷歌地图中的饼图使用 plotGoogleMaps

标签 r google-maps coordinates pie-chart

我正在尝试在坐标列表中添加一些饼图。请在附件中找到我正在使用的数据:
https://www.dropbox.com/sh/834f4ztfnv1o394/g9NbU8WeFt

基本上我正在使用这段代码:

data<-read.csv(file.choose(),header=T)  
coordinates(data) = ~ x + y  
proj4string(data) = CRS("+proj=longlat +datum=WGS84") 
mychart<-segmentGoogleMaps(data, zcol=c('City','Village'),mapTypeId='ROADMAP',  
   filename='myMap4.htm',colPalette=c('#E41A1C','#377EB8'), strokeColor='black') 

但是带有图例的 map 显示时没有任何点或饼图。

请指教

最佳答案

使用下面的解决方案,您将在 map 中获得小条形图(出于某种原因,饼图不起作用;此外,在我看来,饼图并不是一种可视化数据的好方法)。

# loading the required packages
require(reshape2)
require(ggplot2)
require(ggmap)
require(ggsubplot)

# preparing the data
df <- read.csv("sample.csv")
df$id <- sprintf("%02.0f", seq(1,36))
df <- df[,c(5,1,2,3,4)]
colnames(df) <- c("id","lat","lon","City","Village")
dfl <- melt(df, id=c("id","lat","lon"))

# getting the center point of the maps
mean(df$lat) # = 20.03142
mean(df$lon) # = 41.12421

# creating the map with the barplots
albahah <- get_map(location = c(lon = 41.12421, lat = 20.03142), zoom = 8, maptype = "roadmap", scale = 2)

ggmap(albahah) +
  geom_subplot(data = dfl, aes(x = lon, y = lat, group = id,
                               subplot = geom_bar(aes(x = variable, y = log10(value),
                                                      fill = variable), stat = "identity")))

结果:
enter image description here

我对条形图的 y 轴使用了对数刻度,因为否则小值的条形图将几乎不可见。

我希望这有帮助!

关于r - 谷歌地图中的饼图使用 plotGoogleMaps,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23014261/

相关文章:

javascript - loadFromWaypoints 使用 Google Maps API v2 超过 25 个点

javascript - 地点自动完成库中的 IP 位置偏差

javascript - 我如何从 JSON Google map 获取纬度和经度坐标

java - 生成一个偏离两极的随机纬度

r - 如何使用 dplyr 熔化和类型转换数据框?

r - 如何更新多列 XTS 对象中的一行?

R - 在 R 中通过省略号传递列名称

python - BeautifulSoup:根据前面标签的内容打印 div

javascript - 如何用 JavaScript 创建扫雷板?

r - 提取因子水平时的意外行为