Does anyone have experience of changing the order of legend elements when using tm_fill
?
I created a map using tm_polygon
and tried breaks
and labels
to change the order. Both of them failed.
Please see examples below. gov_reg_update
is the sf
object.
head(gov_reg_update)
Simple feature collection with 6 features and 1 field
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: 24.69451 ymin: 21.99913 xmax: 36.90871 ymax: 31.66855
Geodetic CRS: WGS 84
# A tibble: 6 x 2
region_gams geometry
<chr> <MULTIPOLYGON [°]>
1 e-delta (((31.22864 30.05246, 31.22419 30.07381, 31.21677 30.06491, 31.22344 30.03963, 31.22...
2 m-delta (((31.2195 31.15309, 31.21099 31.15603, 31.20113 31.15235, 31.19361 31.1579, 31.1728...
3 m-egypt (((30.99183 28.90639, 30.99953 28.91931, 30.99231 28.9239, 30.98534 28.91505, 30.979...
4 others (((28.53467 27.67273, 28.46664 27.67461, 27.36089 27.67578, 27.83086 28.57875, 28.46...
5 u-egypt (((32.8852 24.46148, 32.88283 24.45191, 32.89828 24.45578, 32.90756 24.45386, 32.915...
6 w-delta (((30.83602 30.48546, 30.82963 30.49857, 30.83614 30.51551, 30.84493 30.52367, 30.85...
Here are the codes I used to draw the map. As can be seen from the image below, the order of the legend elements does not match what I specified in breaks
. Any ideas?
tm_shape(gov_reg_update) +
tm_polygons('region_gams', title = 'Regions',
breaks = c('u-egypt','m-egypt','e-delta','m-delta','w-delta'))
Thanks.