Skip to content

Instantly share code, notes, and snippets.

@csgillespie
Created September 29, 2017 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csgillespie/0d2ca3b99587fca3d8bec57e9f622409 to your computer and use it in GitHub Desktop.
Save csgillespie/0d2ca3b99587fca3d8bec57e9f622409 to your computer and use it in GitHub Desktop.
Comparison of plotly and gpglotly
library(plotly)
library(reshape2)
compare_func_time = function(number = 1, N = 5000){
df = data.frame(matrix(nrow = N, ncol = 11, data = c(rnorm(10*N,10), rnorm(N,30,10))))
colnames(df) = paste0("dist", 1:11)
st1 = system.time({
replicate(number, {
l = list()
for(i in 1:11){
d = density(df[,i])
l[[i]] = data.frame(x = d$x, y = d$y)
}
plot_ly() %>%
add_lines(data = l[[1]], x = ~x, y = ~y) %>%
add_lines(data = l[[2]], x = ~x, y = ~y) %>%
add_lines(data = l[[3]], x = ~x, y = ~y) %>%
add_lines(data = l[[4]], x = ~x, y = ~y) %>%
add_lines(data = l[[5]], x = ~x, y = ~y) %>%
add_lines(data = l[[6]], x = ~x, y = ~y) %>%
add_lines(data = l[[7]], x = ~x, y = ~y) %>%
add_lines(data = l[[8]], x = ~x, y = ~y) %>%
add_lines(data = l[[9]], x = ~x, y = ~y) %>%
add_lines(data = l[[10]], x = ~x, y = ~y) %>%
add_lines(data = l[[11]], x = ~x, y = ~y)
})
})
print("and now st2...")
st2 = system.time({
replicate(number,
{
df_m = melt(df)
ggplotly(ggplot(df_m)+ geom_density(aes(x = value, fill = variable)))
})
})
return(c(st1[3], st2[3]))
}
times = compare_func_time(10)
times
times[2]/times[1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment