Created
February 6, 2015 20:33
-
-
Save bearloga/c9eea0d3179b0b7fb258 to your computer and use it in GitHub Desktop.
Sometimes you just want to send a report to someone as a single HTML file (e.g. when PDF isn't an option) and you want to avoid the hassle of external images. This code lets you convert a plot in R into base64 string that you can include in the HTML source.
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(base64) # install.packages('base64') | |
pngfile <- tempfile() | |
png(pngfile,width=600,height=600,pointsize=12) # adjust as needed | |
# Plotting code... | |
dev.off() | |
# Prints the HTML code to console | |
cat(img(pngfile)) | |
# Copy and paste the whole output into your HTML source to embed the image | |
unlink(pngfile) # clean up |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment