I have a time series data (currently on monthly frequency) from 2014 up to 2020. That means at most 84 monthly values.
For example when plotting (two of categories from the time series data) using geom_tile, I would have a visual below.
ID <- rep(c('A','B','C'),each = 84)
n <- rep(round(runif(84,1,4)), 3)
datetime <- rep(seq(as.POSIXct("2014-01-01"), as.POSIXct("2020-12-01"), by="month"), 3)
df <- tibble(ID,n, datetime)
ggplot(df ,
aes(x=datetime,y=ID,fill=n))+
geom_tile() +
scale_y_discrete(expand=c(0,0)) +
scale_fill_viridis()
I want the rectangle to be a square, so I add on coord_equal()
to my ggplot
,
but somehow the heatmap collapses along the Y-axis
ggplot(df ,
aes(x=datetime,y=ID,fill=n))+
geom_tile() +
scale_y_discrete(expand=c(0,0)) +
scale_fill_viridis() + coord_equal()
The expectation is something like below. As you can see, the squares are of equal size across.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…