Stacking overlapping tiles using geom_tile()

356 Views Asked by At

I'm trying to figure out how to place tiles that represent points using geom_tile(), and my issue is that overlapping tiles only appear as one tile. I'm trying to get tiles with the same y-values to be adjacent to each other, even though they have the same value. My initial thought was to use position = "dodge", however that spread out the tiles all over my bar graph.

My current code is

ggplot(dataset, aes(x = Country, y = `Health Sciences`)) + 
  geom_bar(stat = "identity", width = 0.25) +
  geom_tile(dataset_long, mapping = aes(x = Country, y = Percent, fill = Subject), 
            position = position_dodge(width=0, preserve = "total")) +
  coord_flip()

but it doesn't produce the intended effect. The graph below shows some tiles that are "stacked" atop one another if they have overlapping values, however, I'm trying to get them to be directly adjacent to each other instead. Any help would be appreciated, thanks!

Graph with stacked tiles

0

There are 0 best solutions below