I have trouble with drawing a vertical line in discrete (factor) levels in the x axis of my plot. in this solution it seems to working drawing vertical line with factor levels in ggplot2
but OTH this is not working with geom_tile
?
Basically, to remove the white space in the geom_tile I need to convert to numeric
x values to factor levels . But at the same time I want to draw a geom_vline
with a numeric value.
here is what is the problem
df <- data.frame(
x = rep(c(2, 5, 7, 9, 12), 2),
y = rep(c(1, 2), each = 5),
z = factor(rep(1:5, each = 2)))
library(ggplot2)
ggplot(df, aes(x, y)) +
geom_tile(aes(fill = z), colour = "grey50")+
geom_vline(aes(xintercept=6),linetype="dashed",colour="red",size=1)
to remove white space in geom_tile
need to convert to x to factor(x)
but when I do this geom_vline disappears!