In R, I have hexbins / tilegrams representing jurisdictions of a Canadian province, but the ID labels of hexbins are sitting on the polygons' corners, not inside them.
The closest I got to the desired chart:
I have been messing with geom_polygon
, geom_text
and geom_label
and a few others, but nothing will do. I have seen people use rgeos
for doing this with US statebins but I am guessing this is not necessary in my case, as R does recognise that my hexbins have some ID attached to them, it's just placing them not where I want them. I also tried changing the position argument within geoms.
tileGram_f <- ggplot2::fortify(tileGram2)
tileGram_f <- plyr::join(tileGram_f, tileGram2@data[,c("id", "tile_region")],by="id")
names(tileGram_f)[names(tileGram_f)=="tile_region"] <- "Country"
ggplot(tileGram_f) +
geom_polygon(aes(long, lat, group = group),
fill = "yellow", color = "blue", show.legend = FALSE, size = 1) +
coord_equal() +
geom_text(data = tileGram_f,
aes(x = long, y = lat, label = Country),
size = 8, color = "red", check_overlap = TRUE) +
theme(panel.background = element_blank(),
axis.title = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank())
The hexbins' IDs are made visible by geom_text()
or geom_label()
successfully (ID numbers, 0-21), but they are placed on each of a polygon / hexbin corner. I want them only ONCE per hexbin and inside it, not around it.