Tôi muốn tạo ra một barplot cho mỗi vị trí trên bản đồ bằng ggplot2, như đã được thực hiện bằng cách xingmowang với đồ họa cơ bản và một số gói:Vẽ sơ đồ thanh trên bản đồ bằng ggplot2?
http://nzprimarysectortrade.wordpress.com/2011/10/02/let-r-fly-visualizing-export-data-using-r/
Đây là liên quan đến Embedding a miniature plot within a plot.
Đối với thời điểm này, tốt nhất mà tôi có thể làm là giá trị phù hợp để chỉ kích thước trong một âm mưu điểm jittered:
require(ggplot2)
require(maps)
#Get world map info
world_map <- map_data("world")
#Creat a base plot
p <- ggplot() + coord_fixed()
#Add map to base plot
base_world <- p + geom_polygon(data=world_map,
aes(x=long,
y=lat,
group=group))
#Create example data
geo_data <- data.frame(long=c(20,20,100,100,20,20,100,100),
lat=c(0,0,0,0,0,0,0,0),
value=c(10,30,40,50,20,20,100,100),
Facet=rep(c("Facet_1", "Facet_2"), 4),
colour=rep(c("colour_1", "colour_2"), each=4))
#Creat an example plot
map_with_jitter <- base_world+geom_point(data=geo_data,
aes(x=long,
y=lat,
colour=colour,
size=value),
position="jitter",
alpha=I(0.5))
#Add faceting
map_with_jitter <- map_with_jitter + facet_wrap(~Facet)
map_with_jitter <- map_with_jitter + theme(legend.position="none")
print(map_with_jitter)
Với một workaround thanh nha:
subset_data <- geo_data[geo_data$Facet=="Facet_1" &
geo_data$long=="20",]
subplot <- qplot(data=subset_data,
x=colour,
y=value,
fill=colour,
geom="bar",
stat="identity")+theme(legend.position="none")
print(base_world)
print(subplot, vp=viewport((200+mean(subset_data$long))/400,(100+mean(subset_data$lat))/200 , .2, .2))
câu hỏi liên quan: http://stackoverflow.com/questions/10368180/plotting-pie-graphs-on-map-in-ggplot –
câu hỏi là gì ở đây? Bạn đã thử cái gì? –
xem '? Annotation_custom' để biết ví dụ về hình ảnh inset – baptiste