I haven't found any history questions about this... I want to highlight the weekend performance for a ggplot graph, so that user could tell directly one the graph which part(may be a gray shade?) is weekend performance right away.
Here's a simple version of testing data:
test <- data.frame(DATE=seq(from = as.POSIXct("2014-07-16 01:00"), to = as.POSIXct("2014-07-30 00:00"), by = "hour"),count=floor(runif(336,1,100)))
Simple version of my graph is:
ggplot() + geom_line(aes(x=DATE,y=count),data=test) + labs(title="test")
So that result could be like something below...
Using geom_area() is more concise, and will work for any date range.
library(ggplot2)
test <- data.frame(DATE=seq(from = as.POSIXct("2014-07-16 01:00"),
to = as.POSIXct("2014-07-30 00:00"),
by = "hour"),
count=floor(runif(336,1,100)))
test$weekend <- weekdays(test$DATE) %in% c("Saturday", "Sunday")
ggplot(data=test, aes(x=DATE, y=count)) +
geom_area(aes(y=weekend*max(count)), fill="yellow") +
geom_line() +
labs(title="test")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With