Just another way to make a R flavored blog

[This article was first published on Jkunst - R category , and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

This post is in active development!


image source

This usually is "echo=FALSE"

rm(list = ls())
library("printr")
knitr::opts_knit$set(root.dir  = normalizePath(".."))

Considerations

  1. Use h2 ## in R files to spin, because h1 is reserved for title post.
  2. At the begin of R script write a chunk of R code loading the print package
  3. This post have some considerations to have when write a post via:
    r script > spind > md and testing r srcipt > html_fragment:
print(getwd())
## [1] "C:/Users/Joshua K/Documents/Dev/jbkunst.github.io"
print(knitr::opts_knit$get("root.dir"))
## [1] "C:\Users\Joshua K\Documents\Dev\jbkunst.github.io"

this should be equal when knit via ctrl+ shift + K

Testing knitr::spin on this R script

Load libraries

library("ggplot2")
library("ggthemes")
library("dplyr")

this is how we show tables

test <- sample_n(diamonds, 1000)
head(test)
caratcutcolorclaritydepthtablepricexyz
430080.57IdealGSI160.55713695.405.373.26
170151.25IdealJVS161.25667936.936.954.25
453400.57IdealGSI162.05516625.355.323.31
287720.33Very GoodDVS262.5596814.394.412.75
351440.38IdealFVS261.2578894.674.642.85
125490.95GoodEVS257.75852726.476.523.75

And this is who we can plot! 😀

p <- ggplot(test) +
  geom_point(aes(x = carat, y = price, color = price, shape = cut)) +
  facet_wrap(~color) + 
  theme_fivethirtyeight() + 
  scale_color_continuous_tableau() + 
  theme(legend.position = "none")
p

plot of chunk ploting

This is a h3!

I can load a data

mtcars <- readr::read_csv("data/mtcars.csv")

Showing a table

head(mtcars)
mpgcyldisphpdratwtqsecvsamgearcarb
21.061601103.902.6216.50144
21.061601103.902.8817.00144
22.84108933.852.3218.61141
21.462581103.083.2119.41031
18.783601753.153.4417.00032
18.162251052.763.4620.21031

According with http://yihui.name/knitr/options/, dpi: (72; numeric) the
DPI (dots per inch) for bitmap devices (dpi * inches = pixels) so:

desire_width_px <- 720
desire_height_px <- 480
dpi <- 72
fig.width <- desire_width_px / dpi
fig.height <- desire_height_px / dpi

fig.width
## [1] 10
fig.height
## [1] 6.67

This template need a 720 x 480 image. So at the final of the script
I generate a chunk named featured_image, with parameters: echo=FALSE,
fig.width=10, fig.height=6.7, dpi=72 and fig.show='hide'.

Markdown references

  1. http://milanaryal.com/2015/writing-on-github-pages-and-jekyll-using-markdown/
  2. http://ajoz.github.io/2014/06/29/i-want-my-github-flavored-markdown/
  3. https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#line-breaks
  4. https://george-hawkins.github.io/basic-gfm-jekyll/redcarpet-extensions.html#hard-wrap

To leave a comment for the author, please follow the link and comment on their blog: Jkunst - R category .

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)