I have a dataframe and I want to plot with geom_tile
and fill according to the "ID" variable in the data, but I find that fill
is not working in my code. Thanks for any help.
set.seed(1234)
x <- sample(x=-2288200:3076160, size = 1000,replace = F)
y <- sample(x=353334.1:4803914.0, size = 1000,replace = F)
ID <- sample(x=1:4, size = 1000,replace = T)
Mydata <- data.frame(x=x,y=y,ID=factor(ID))
group.colors <- c("1"="red","2"="yellow","3"="blue","4"="green")
ggplot() + geom_tile(data = Mydata, aes(x = x, y = y, fill=ID)) +
scale_fill_manual(values = group.colors,name = "group")