I have the following data:
Id = paste ("ID-", 1:5, sep = "") position <- rep(seq (1, 100,10), each = 5) group = rep (rep(rep (1:5, each = length (Id)), each = length(position))) yvar <- rnorm (length(position), 0.5, 0.1) ycat <- c(sample (c("A", "B"), length(yvar), replace = TRUE)) namevar <- rep(Id, length(group)/length(Id)) mydf <- data.frame (namevar, group, position, yvar, ycat)
group
is a faceted variable, position
is a continuous variable x. yvar
used to fill the color of tiles. ycat
is the text label for each fragment. I want to create a plot with empty space for all values except certain fragments that I choose to build with fill color and labels.
Here is what I still have:
ggplot(mydf,aes(y=Id,x=position)) + facet_wrap(~group) + geom_tile(aes(fill = yvar),colour = "black") + geom_text(aes(label = ycat)) + labs(x = NULL,y = NULL)
I would like this plot to look like it is an empty place all over the world, with the exception, for example, of group 1 between 30-50 and group 5 between 20-60, like: