Consultation related to drawing heat map

Dear friends, I want to draw the heat map as shown below:


But the two pictures obtained by using the following code are not very suitable.

#load(example.data)
ggplot(example.data, aes( x=date, y=scales, fill=DI) ) +
geom_tile(width=100) +
scale_fill_continuous(type = "viridis")+
labs(title = 'Fig.1')
d <- dcast(example.data, date ~ scales )
d <- d[,-1]
image(x=unique(example.data$date),y=unique(example.data$scales),
z= as.matrix(d), col = heat.colors(81),
xlab='date',ylab='scales',main='Fig.2' )

The two figures obtained from the above code are as follows:


Please help me to find out what the problem is? Thank you very much!
Another question needs to be asked. How should I upload the data required by this code (the example.data is a data.table of 16152*3)?

1 Like

it looks to me like your x axis represents both date and time, when you need it to be date only (based on the axis numbers, dates would be around 20000). y is then the time...
Re sharing the data, you could use dput to output the first month or something like that...

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.