【问题标题】:Adding fixed size breaks with tmap tm_bubble使用 tmap tm_bubble 添加固定大小的中断
【发布时间】:2019-06-16 14:24:06
【问题描述】:

我正在尝试创建一个 tmap 气泡图,其中大小和颜色美学具有相同的固定中断。设置style = "fixed"breaks = c(-Inf, seq(-10, 10, by = 2.5), Inf) 会为颜色变量产生所需的结果,但大小变量保持不变。我正在处理具有正值和负值的数据,因此我使用了具有色彩美学的发散调色板。我在绘制它的大小时使用了这个变量的绝对值。我想在 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))

【问题讨论】:

  • 您能否添加dput(head(data)) 的输出,以便我们为您提供帮助?
  • 感谢您的建议。我现在添加了一个代表。
  • 这可能是相关的吗? - tm_symbols/tm_bubbles size?
  • 这为我指明了正确的方向。虽然仍在研究解决方案。谢谢!
  • @philiporlando 嗨!我也有同样的问题。你碰巧找到答案了吗?谢谢!

标签: r ggplot2 tmap


【解决方案1】:

上面评论中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 将定义人口的中断

【讨论】:

    猜你喜欢
    • 2019-12-20
    • 2013-09-07
    • 1970-01-01
    • 2019-08-01
    • 2021-02-23
    • 2015-09-06
    • 1970-01-01
    • 1970-01-01
    • 2014-06-09
    相关资源
    最近更新 更多