Consider this example:
library(dplyr)
library(sf)
library(tmap)
d <- data_frame(one = c(1,1,2,1,1,1,1),
two = c(1,1,2,1,1,1,1))
std <- st_as_sf(d, coords = c('one', 'two'))
std %>% tm_shape() + tm_bubbles(alpha = 0.3)
You can see that point (1, 1)
is darker because it appears 6 times in the data. Therefore, thanks to the alpha
blending, these points add-up.
My problem is that I cannot store the dataset as it. What I have is only an aggregated version, like
d_agg <- d %>% group_by(one, two) %>%
summarize(count = n()) %>%
ungroup()
# A tibble: 2 x 3
one two count
<dbl> <dbl> <int>
1 1 1 6
2 2 2 1
How can I reproduce the same exact chart as before, using d_agg
and the corresponding count
variable?
Of course, re-creating the initial dataframe above is not feasible solution because I have too many points (and some points are repeated too many times)
Just using:
std_agg %>% tm_shape() + tm_bubbles(col = 'count', alpha = 0.3)
does not work