我正在尝试在坐标列表中添加一些饼图。请附上我正在使用的数据: 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')
但是带有图例的地图会显示没有任何点或饼图。
请告知
答案 0 :(得分:3)
通过下面的解决方案,您将获得地图中的小条形图(由于某些原因,饼图无法正常工作;而且在我看来,饼图并不是一种非常好的可视化数据方式。)
# 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")))
结果:
我在条形图的y轴上使用了对数刻度,因为小值的条形图几乎是不可见的。
我希望这有帮助!
答案 1 :(得分:2)