I am trying to make a heatmap using R ggplot, and the desired outcome graph is like below. I have different age ranges by each study, but I would like to fix the age range from 0 to 100 by 10 years old like this graph. I would like to populate the prevalence tiles by the defined age ranges in the raw data I have, but currently I am unable to populate the prevalence rates by the age ranges that are in the raw data. enter image description here
my data frame looks like this: enter image description here
This graph is the one that I made right now, with the x axis age range enter image description here
ggplot(CountryModel, aes(x = age, y = country, fill = prevalence)) +
geom_tile(width = 0.9, height = 0.1) + # adjust width and height of tiles
facet_wrap(~ region, ncol = 1, scales = "free_y") +
scale_fill_gradient(low = "white", high = "red", limits = c(0, 100), na.value = "gray") + # fill the color for missing values
labs(x = "Age Group", y = "Subgroup", fill = "Value") +
theme_dark() +
theme(panel.spacing.y = unit(0.1, "lines"), # adjust spacing between panels
axis.line = element_blank(), # remove axis lines
axis.text.x = element_text(angle = 45, hjust = 1), # rotate x-axis labels
axis.ticks = element_blank(), # remove axis ticks
strip.background = element_rect(fill = "gray10"), # change background color of strip
strip.text = element_text(color = "white"), # change color of strip text
panel.grid = element_blank(), # remove panel grid
legend.position = "bottom")+ # move legend to the bottom
geom_vline(xintercept = seq(0,100,10), color = "grey")
the above is the code that I made.
I would appreciate your help!!