mapview
mapview copied to clipboard
Mismatched colors between legend and points on map
Hi Tim,
I would like to contrast successive groups of points on a map by using alternating colors.
library('mapview')
library('sf')
sp <- structure(list(Date = structure(c(1523356740, 1523361120, 1523367540, 1523477580, 1523481900, 1523483820, 1523487300,
1523487900, 1523489520, 1523490240, 1523492940, 1523496300, 1523577900, 1523579040, 1523581500, 1523583900, 1523602260,
1523688120, 1523694060, 1523698740, 1523700120, 1523702340, 1523703900, 1523704860, 1523708100, 1523710020, 1523711700,
1523714040, 1523795700, 1523799240, 1523820360, 1523826360, 1523827260, 1523827920, 1523906040, 1523911740, 1523912340,
1523912400, 1523918220, 1523918400, 1523921760, 1523924640, 1523927940, 1523928000, 1523930580, 1524015360, 1524037020,
1524042720, 1524043320, 1524128820, 1524132780, 1524133320, 1524138420, 1524138660, 1524139920, 1524143400, 1524144420,
1524145860, 1524237060, 1524254460, 1524262560, 1524263880, 1524264600, 1524346800, 1524347100, 1524348780, 1524350280,
1524352920, 1524354480, 1524355980, 1524356400, 1524359940, 1524362400, 1524365820, 1524465600, 1524471420, 1524471540,
1524477480, 1524477720, 1524478380, 1524481320, 1524484440, 1524486480, 1524487320, 1524566940, 1524568020, 1524569400,
1524571740, 1524573060, 1524574920, 1524577620, 1524581040, 1524583560, 1524597600, 1524683460, 1524689340, 1524691260,
1524694320, 1524697200, 1524698700, 1524700140, 1524703020, 1524705180, 1524706620, 1524787620, 1524788160, 1524790740,
1524791820, 1524793800, 1525466760, 1525470060, 1525475700, 1525476120, 1525476300, 1525558620, 1525560480, 1525560780,
1525562040, 1525566600, 1525566660, 1525567140, 1525567800, 1525569720, 1525572480, 1525677840, 1525683720, 1525690440,
1525691220, 1525693140, 1525699320, 1525779000, 1525782060, 1525784940, 1525788000, 1525809480, 1525894980, 1525901340,
1525904580, 1525906320, 1525910460, 1525910580, 1525912440, 1525913160, 1525916520, 1525917000, 1525918800, 1525997580,
1526001540, 1526003940, 1526007420, 1526010000, 1526026500), class = c("POSIXct", "POSIXt"), tzone = ""),
Latitude = c(-21.129, -21.128, -21.124, -20.617, -20.619, -20.621, -20.731, -20.763, -20.843, -20.852, -20.944, -20.787,
-20.998, -20.985, -20.986, -20.991, -21.022, -20.178, -19.828, -19.677, -19.676, -19.485, -19.422, -19.425, -19.345, -19.416,
-19.398, -19.422, -18.318, -18.319, -18.359, -18.364, -18.378, -18.373, -18.51, -18.515, -18.554, -18.524, -18.61, -18.547,
-18.567, -18.572, -18.565, -18.592, -18.585, -18.088, -17.81, -17.649, -17.789, -17.46, -17.331, -17.327, -17.318, -17.322,
-17.31, -17.29, -17.29, -17.34, -17.416, -17.458, -17.473, -17.485, -17.536, -17.995, -17.967, -17.915, -17.863, -17.703, -17.682,
-17.637, -17.613, -17.578, -17.475, -17.316, -17.96, -17.772, -17.864, -17.824, -17.868, -17.903, -17.914, -17.988, -17.978,
-18.018, -17.129, -16.959, -16.961, -16.957, -16.971, -16.972, -16.858, -16.815, -16.582, -16.582, -16.029, -15.975, -15.946, -15.94,
-15.967, -15.973, -16.054, -15.991, -16.247, -16.083, -15.106, -15.187, -15.07, -15.058, -14.892, -10.75, -10.733, -10.819, -10.822,
-10.837, -10.652, -10.695, -10.742, -10.772, -10.819, -10.82, -10.793, -10.826, -10.776, -10.765, -10.062, -9.923, -9.868, -9.873,
-9.858, -9.805, -9.125, -9.123, -9.085, -9.079, -9.046, -8.156, -8.075, -8.077, -7.976, -7.843, -7.834, -7.61, -7.734, -7.748, -7.63,
-7.803, -6.798, -6.77, -6.697, -6.671, -6.633, -6.429),
Longitude = c(55.998, 55.996, 55.996, 56.666, 56.665, 56.755, 56.863, 56.946, 56.949, 56.962, 57.239, 56.624, 57.882,
57.889, 57.858, 57.836, 57.607, 56.899, 57.08, 56.965, 57.078, 56.913, 56.892, 56.9, 56.836, 56.805, 56.77, 56.782, 56.112,
56.105, 55.965, 55.948, 55.935, 55.927, 55.716, 55.64, 55.7, 55.705, 55.911, 55.63, 55.674, 55.676, 55.663, 55.753, 55.695,
55.451, 55.615, 55.74, 55.707, 55.888, 55.926, 55.915, 55.912, 55.902, 55.898, 55.905, 55.896, 55.834, 55.459, 55.417, 55.371,
55.277, 55.334, 55.236, 55.195, 55.194, 55.187, 55.129, 55.051, 55.08, 55.048, 55.063, 54.952, 55.007, 54.324, 54.455, 54.385,
54.377, 54.405, 54.488, 54.383, 54.42, 54.427, 54.397, 54.193, 54.284, 54.292, 54.365, 54.44, 54.43, 54.28, 54.268, 54.129,
54.024, 53.632, 53.597, 53.573, 53.491, 53.397, 53.327, 53.203, 53.238, 53.203, 53.244, 53.342, 53.464, 53.378, 53.542,
53.554, 49.836, 49.814, 49.544, 49.519, 49.564, 48.301, 48.271, 48.104, 48.043, 47.962, 47.968, 47.836, 47.869, 47.854, 47.827,
46.931, 47.165, 47.127, 47.115, 47.115, 47.121, 47.079, 47.068, 47.07, 47.051, 46.93, 46.878, 46.771, 46.814, 46.921, 47.016,
47.031, 47.082, 47.057, 47.041, 46.855, 47.132, 48.096, 48.209, 47.916, 48.23, 48.254, 48.375),
point.group = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 14L,
14L, 14L, 14L, 14L, 15L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 17L, 17L, 17L, 17L, 17L,
17L, 18L, 18L, 18L, 18L, 18L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 20L, 20L, 20L, 20L, 20L, 20L), .Label = c("1", "2",
"3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"), class = "factor")),
row.names = 397:246, class = "data.frame")
sp2 <- st_as_sf(sp,
coords = c('Longitude', 'Latitude'),
crs = "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0")
mapview(sp2,
zcol = 'point.group',
col.regions = ifelse(as.integer(as.character(unique(sp2$point.group))) %% 2, 'dodgerblue4', 'olivedrab'))
Problems are: 1 - color of legend don't fit the point colors on map 2 - the group of points 17 & 18 have the same color on the map.
I carefully read issue #362 and I wonder if I missed something ?
Thanks a lot,
Claire