By Riddhiman
Just because we all like numbers doesn’t mean we can’t have some fun.
Here’s to wishing to everyone a very Happy New Year !
# install.packages("jpeg")
library(jpeg)
library(plotly)
# Download a jpeg file from imgur
URL "http://i.imgur.com/FWsFq6r.jpg"
file tempfile()
download.file(URL, file, mode = "wb")
# Read in JPEG file
j readJPEG(file)
j j[,,1]
# Create an empty matrix
img.mat mat.or.vec(nrow(j), ncol(j))
# Identify elements where there is data
idx j > 0
# Add some glitter like effect
img.mat[idx] sample(x = seq(0,1,by = 0.1), size = sum(idx), replace = T)
# Add some glitter to background
idx j == 0
img.mat[idx] sample(seq(0.7,0.9,0.01), size = sum(idx), replace = T)
# Invert the matrix or else it prints upside down
img.mat[nrow(img.mat):1,] img.mat[1:nrow(img.mat),]
# Plot !!!
x.axisSettings list(
title = "Learn from yesterday, live for today, hope for tomorrow. The important thing is not to stop questioning. -Albert Einstein",
titlefont = list(
family = 'Arial, sans-serif',
size = 12,
color = 'black'
),
zeroline = FALSE,
showline = FALSE,
showticklabels = FALSE,
showgrid = FALSE,
ticks = ""
)
y.axisSettings list(
title = "",
zeroline = FALSE,
showline = FALSE,
showticklabels = FALSE,
showgrid = FALSE,
ticks = ""
)
bordercolor = "#ffa64d"
borderwidth = 20
nCol = ncol(img.mat)
nRow = nrow(img.mat)
plot_ly(z = img.mat, colorscale = "Hot", type = "heatmap", showscale = F, hoverinfo = "none") %>%
layout(xaxis = x.axisSettings,
yaxis = y.axisSettings,
# Add a border
shapes = list(
# left border
list(type = 'rect', fillcolor ...read more
Source:: r-bloggers.com