reformatting x axis as date in a heat map in ggplot

279 Views Asked by At

I am trying to make a heat map using ggplot and I am having trouble formatting the x axis as a date.
When I run the basic code

ggplot(kbsdiv13CTN, aes(x=date, y=rev(depth), fill=mean)) + geom_tile() + scale_fill_gradient(low = "white", high = "black") + scale_y_reverse()
The heat map looks ok, but the dates are in the wrong order, and the x axis labels are really crowded together.

But then I reformat the x axis as date kbsdiv$date<- as.Date(kbsdiv$date , format = "%m/%d")

ggplot(kbsdiv13CTN, aes(x=date, y=rev(depth), fill=mean)) + geom_tile() + scale_fill_gradient(low = "white", high = "black") + scale_y_reverse() + scale_x_date(breaks = date_breaks("weeks"),labels = date_format("%b")) . and the heat map tiles become really narrow and no longer fill up the image. They basically look like very narrow bars, and it no longer looks like a heat map. I wanted to post a picture but they would not let me.

Can someone help?

0

There are 0 best solutions below