1

I am doing some data visualisation on financial time series.

I basically want the heatmap below, but without the hour axis, i.e., 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:

enter image description 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))
JHolmes
  • 23
  • 6
  • 1
    why don't you create a variable that is the mean price per day and use that as the x? – Carbo Jan 27 '20 at 14:33
  • Ok, not sure how to calculate that in R. If I want to find mean of price change, I'll have to add something like 'if Day = "Monday"'? – JHolmes Jan 27 '20 at 14:36
  • 2
    Can you provide a reproducible example of your data ? https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – dc37 Jan 27 '20 at 14:42
  • @Carbo, maybe it will be more readable if you post your comments as an answer ;) – dc37 Jan 27 '20 at 15:04
  • @dc37 you're right – Carbo Jan 27 '20 at 15:08

1 Answers1

0

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))
Carbo
  • 906
  • 5
  • 23