Last active
April 13, 2019 12:48
-
-
Save RodrigoSC/1f8749da7cfd5293aab84bd01ccba79b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
library(ggplot2) | |
library(RColorBrewer) | |
# Create the dataset ---- | |
set.seed(123) | |
df <- data.frame(helper = c(rnorm(500, 120, 100), | |
rnorm(500, 1, .8))) %>% | |
mutate(elapsed = cumsum(helper), | |
date = as.POSIXct('2019-05-25 10:00:00') + elapsed, | |
event = 'Ping') %>% | |
select(date, event) | |
# Transform the dataset ---- | |
before_after <- df %>% | |
arrange(date) %>% | |
mutate(before = as.numeric(date - lag(date)), | |
after = as.numeric(lead(date) - date)) %>% | |
filter(!is.na(before) & !is.na(after)) | |
# Plot the dataset ---- | |
axis_labels = list('1/100s' = 0.1, '1 sec' = 1, '1 min' = 60, | |
'2 min' = 120, '10 min' = 600) | |
ggplot(before_after, aes(x = before, y = after)) + | |
geom_hex() + | |
scale_fill_gradientn(colours = rev(brewer.pal(5, "Spectral"))) + | |
scale_y_continuous(trans = "log10", minor_breaks = NULL, | |
breaks = unlist(axis_labels), | |
labels = names(axis_labels)) + | |
scale_x_continuous(trans = "log10", minor_breaks = NULL, | |
breaks = unlist(axis_labels), | |
labels = names(axis_labels)) + | |
theme(axis.text.x = element_text(angle = 45, hjust = 1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment