我在R中繪製了一個地圖,繪製了幾個城市的點大小由人口決定;它是疊加在Tirgris/Line Shapefiles上的氣泡圖。一切工作都很好,除了傳說對於可能的數據沒有很好的規模。我有幾個社區,約800-1100人,一個約2000人,另外兩個約25000 +。 ggplot創造的傳說有10000,20000和30000人口的泡沫。我希望它是2000,20000,& 30000之類的東西。我做了很多研究,但沒有發現任何有希望的東西。修改ggplot2氣泡圖的圖例比例尺
library(ggplot)
library(rgdal)
library(tigris)
cities.data = read.csv("cities.csv", header = TRUE)
latah.mp <- county_subdivisions(state = '16', county = '057', cb = TRUE) # reads TIGER/Line data from US Census for Latah County
whitman.mp <- county_subdivisions(state = '53', county = '075', cb = TRUE) # reads TIGER/Line data from US Census for Whitman County
region.mp = rbind_tigris(latah.mp, whitman.mp) # binds county shapefiles into one image
region.map <- fortify(region.mp)
ggplot() +
geom_map(data = region.map, map = region.map, aes(x = long, y = lat, map_id = id), fill = "#CCE5CC", color = "#BBD4BB") +
geom_point(data = cities.data, aes(x = long, y = lat, size = Population), alpha = 0.5, color = "black") +
scale_size_continuous(range = c(1,10)) +
annotate("text", x = -117.163454, y = 46.6827, label = "Pullman", size = 2.5) +
annotate("text", x = -116.998909, y = 46.6827, label = "Moscow", size = 2.5) +
annotate("text", x = -117.311862, y = 46.8897, label = "Colfax", size = 2.5) +
annotate("text", x = -116.772232, y = 46.7075, label = "Troy", size = 2.5) +
annotate("text", x = -117.07534, y = 46.8803, label = "Palouse", size = 2.5) +
annotate("text", x = -116.92887, y = 46.5215, label = "Genessee", size = 2.5) +
annotate("text", x = -117.073984, y = 47.1953, label = "Teko", size = 2.5) +
annotate("text", x = -116.897068, y = 46.8930, label = "Potlatch", size = 2.5) +
theme_classic() +
coord_quickmap() +
theme(axis.line = element_blank(), axis.text.x = element_blank(), axis.text.y = element_blank(), axis.ticks = element_blank(), axis.title.x=element_blank(), axis.title.y=element_blank())
Map of Whitman & Latah Counties
從文件「cities.csv」中的數據低於是否有幫助,能夠全程運行代碼。
city lat long Population
Pullman.WA 46.7327 -117.1635 30851
Tekoa.WA 47.2253 -117.0740 789
Palouse.WA 46.9103 -117.0753 1092
Colfax.WA 46.9197 -117.3119 2826
Potlatch.ID 46.9230 -116.8971 773
Moscow.ID 46.7306 -116.9989 24406
Troy.ID 46.7375 -116.7722 906
Genesee.ID 46.5515 -116.9289 965
也許'scale_size_continuous(range = c(1,10),breaks = c(2000,20000,30000))' – cuttlefish44