我正在尝试创建一个tmap气泡图,其中大小和颜色美学具有相同的固定间隔。设置style = "fixed"
和breaks = c(-Inf, seq(-10, 10, by = 2.5), Inf)
可以为颜色变量产生所需的结果,但是size变量保持不变。我正在处理具有正值和负值的数据,因此我正在使用具有审美色彩的发色调色板。虽然在绘制其大小时使用的是此变量的绝对值。我想在0到10之间创建固定的尺寸间隔,以匹配调色板的绝对值范围。
这是我当前地图脚本的简单版本
# dput(head(df))
points_layer <- structure(list(date = structure(c(17449, 17449, 17449, 17449,
17449, 17449), class = "Date"), node = c("Irvington", "Marion Court Apartments",
"Portsmouth Portland", "PSU STAR Lab Roof North", "PSU STAR Lab Roof South",
"PSU STAR Lab Rose City Park"), pm2_5_cf_x = c(9.25546767003776,
9.45130634372901, 12.6012155894551, 8.74508087500526, 8.42118421108649,
9.22030608712564), pm2.5.predicted = c(9.20049509485525, 8.7580813489583,
11.0618606546844, 7.93370690912048, 7.91343513801979, 9.40375047003665
), geometry = structure(list(structure(c(526751.6, 5043182), class = c("XY",
"POINT", "sfg")), structure(c(528887.8, 5039881), class = c("XY",
"POINT", "sfg")), structure(c(522455.5, 5048089), class = c("XY",
"POINT", "sfg")), structure(c(524503.4, 5040017), class = c("XY",
"POINT", "sfg")), structure(c(524497.7, 5039985), class = c("XY",
"POINT", "sfg")), structure(c(531513.6, 5043473), class = c("XY",
"POINT", "sfg"))), class = c("sfc_POINT", "sfc"), precision = 0, bbox = structure(c(522455.5,
5039881, 531513.6, 5048089), .Names = c("xmin", "ymin", "xmax",
"ymax"), class = "bbox"), crs = structure(list(epsg = 26910L,
proj4string = "+proj=utm +zone=10 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"), .Names = c("epsg",
"proj4string"), class = "crs"), n_empty = 0L), diff = c(-0.0549725751825161,
-0.693224994770707, -1.53935493477068, -0.811373965884778, -0.507749073066702,
0.183444382911013), abs_diff = c(0.0549725751825161, 0.693224994770707,
1.53935493477068, 0.811373965884778, 0.507749073066702, 0.183444382911013
), mape = c(0.593947028311448, 7.33470030024649, 12.2159241213113,
9.27806131792109, 6.02942603248424, 1.9895693394296)), .Names = c("date",
"node", "pm2_5_cf_x", "pm2.5.predicted", "geometry", "diff",
"abs_diff", "mape"), sf_column = "geometry", agr = structure(c(NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_), .Names = c("date", "node", "pm2_5_cf_x", "pm2.5.predicted",
"diff", "abs_diff", "mape"), .Label = c("constant", "aggregate",
"identity"), class = "factor"), row.names = 698:703, class = c("sf",
"data.frame"))
tm_shape(raster_layer) + # ignore the raster for now
tm_raster() + # and ignore this too
tm_shape(points_layer) +
tm_bubbles(col = "diff", size = "abs_diff", style = "fixed",
size.lim = c(0,10), breaks = c(-Inf, seq(-10, 10, by = 2.5), Inf))
答案 0 :(得分:0)
上面注释中的link中提到的sizes.legend
是tm_bubbles
的参数。
如果tm_bubbles
像这样:
tm_bubbles(col='Cost', size='Population',
breaks=seq(0,8, by=2),
sizes.legend=seq(15000, 75000, by=15000))
breaks
将定义“费用”间隔,sizes.legend
将定义“人口”间隔