简体   繁体   中英

Heatmap with just x (or y) axis

I am doing some data visualisation on financial time series.

I basically want the heatmap below, but without the hour axis, ie, I want to show the average price change for each weekday, to see if there is statistically a better chance of appreciation/depreciation on certain days of the week.

My original plot is here:

在此处输入图片说明

My code is:

ggplot(Change , aes(x=Hour, y=Day, fill = Change)) + 
+     geom_tile(color = "white", size = 0.2) + 
+     scale_x_discrete(expand=c(0,0)) + 
+     scale_y_discrete(expand=c(0,0)) + 
+     scale_fill_viridis(name="Price Range", option = "plasma") + 
+     coord_equal() + 
+     labs(x="Hour", y=NULL, title=sprintf("price range by hr")) + 
+     theme_tufte(base_family="Helvetica") +
+     theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1))

maybe you can try to reshape your data frame so that there is just one datapoint per each dat (for instance the sub of the price change, or the price change between the beginning of the day and the end of the day. I think it would be useful to have a reproducible example).

since you didn't provide it, I made am example with 7 days and some time slots

data

day <- c("monday" , "tuesday", "wednsday", "thursday", "friday", "saturday", "sunday") 
dt <- as.data.frame(matrix(c(1,2,3,4,5, 6,7,8,9,10, 1,2,5,4,3, 2,3,5,7,6, 4,8,9,7,8, 9,8,9,9,1, 3,4,3,1,2) , nrow = 5 , ncol=7, byrow=TRUE)) 
colnames(dt) <- c("monday" , "tuesday", "wednsday", "thursday", "friday", "saturday", "sunday") 
rownames(dt) <- c("0:00", "2.00", "4.00", "8.00", "10.00") dt <- as.data.frame(colSums(dt))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM