Skip to content

Instantly share code, notes, and snippets.

View raffdoc's full-sized avatar

Rafik Margaryan raffdoc

View GitHub Profile
@raffdoc
raffdoc / gitbook.R
Created April 20, 2014 14:15 — forked from jbryer/gitbook.R
require(knitr)
#' Initializes a new Gitbook.
#'
#' This will initalize a new Gitbook in the given directory. When done, it will
#' also change the working directory.
#'
#' @author Jason Bryer <jason@bryer.org>
newGitbook <- function(dir) {
# TODO: May want to make these parameters or options
@raffdoc
raffdoc / 000-instructions.md
Created June 19, 2012 20:12 — forked from halpo/000-instructions.md
harvestr R users conference presentation.

Building a beamer presentation with knitr.

Introduction

The documents included are the input for knitr. In addition you need to have the tool pandoc installed. I also use a custom beamer template to add the University of Utah \institute command to the template. It also changes the indentation some.

Steps

  1. knit document with
@raffdoc
raffdoc / instant_pkgs.R
Created June 19, 2012 19:35
Wrapper for package installation and loading
# Script name: instant_pkgs.R
# Purpose: Package installation and loading
# Author: Kay Cichini
# Date: 2012-06-19
# Licence: cc by-nc-sa
instant_pkgs <- function(pkgs) {
pkgs_miss <- pkgs[which(!pkgs %in% installed.packages()[, 1])]
if (length(pkgs_miss) > 0) {
install.packages(pkgs_miss)
\documentclass[nohyper,justified]{tufte-handout}
%\documentclass{article}
%great guides at epslatex.pdf
%check miniplot for potential use
%\usepackage{graphics}
%\usepackage{caption}
%\usepackage{sidecap}
%\usepackage{textpos}
%\usepackage[section]{placeins}
Interactive charts and slides with R, googleVis and knitr
========================================
```{r results='asis', echo=FALSE, message=FALSE, tidy=FALSE}
library(googleVis)
G <- gvisGeoChart(Exports, "Country", "Profit",
options=list(width=250, height=120), chartid="c1")
T <- gvisBarChart(Exports[,1:2], yvar="Profit", xvar="Country",
options=list(width=250, height=260,
legend='none'), chartid="c2")
\documentclass{article}
%great guides at epslatex.pdf
%check miniplot for potential use
\usepackage{graphics}
\usepackage{caption}
%\usepackage{sidecap}
%\usepackage{textpos}
\usepackage[section]{placeins}
@raffdoc
raffdoc / caschools-analysis.rmd
Created May 19, 2012 08:23 — forked from jeromyanglim/caschools-analysis.rmd
California schools analysis demonstrating use of R Markdown
`r opts_chunk$set(cache=TRUE)`
This is a quick set of analyses of the California Test Score dataset. The post was produced using R Markdown in RStudio 0.96. The main purpose of this post is to provide a case study of using R Markdown to prepare a quick reproducible report. It provides examples of using plots, output, in-line R code, and markdown. The post is designed to be read along side the R Markdown source code, which is available as a gist on github.
<!-- more -->
### Preliminaries
* This post builds on my earlier post which provided a guide for [Getting Started with R Markdown, knitr, and RStudio 0.96](jeromyanglim.blogspot.com/2012/05/getting-started-with-r-markdown-knitr.html)
* The dataset analysed comes from the `AER` package which is an accompaniment to the book [Applied Econometrics with R](http://www.amazon.com/Applied-Econometrics-R-Use/dp/0387773169) written by [Christian Kleiber](http://wwz.unibas.ch/personen/profil/person/kleiber/) and [Achim Zeileis](http://eeecon.uibk.ac.at/~zeileis/
@raffdoc
raffdoc / example-r-markdown.rmd
Created May 17, 2012 20:37 — forked from jeromyanglim/example-r-markdown.rmd
Example of using R Markdown
This post examines the features of [R Markdown](http://www.rstudio.org/docs/authoring/using_markdown)
using [knitr](http://yihui.name/knitr/) in Rstudio 0.96.
This combination of tools provides an exciting improvement in usability for
[reproducible analysis](http://stats.stackexchange.com/a/15006/183).
Specifically, this post
(1) discusses getting started with R Markdown and `knitr` in Rstudio 0.96;
(2) provides a basic example of producing console output and plots using R Markdown;
(3) highlights several code chunk options such as caching and controlling how input and output is displayed;
(4) demonstrates use of standard Markdown notation as well as the extended features of formulas and tables; and
(5) discusses the implications of R Markdown.
library(ggplot2)
library(colorRamps)
IliganCity <- c(104493, 118778, 167358, 226568, 273004, 285061, 308046, 322821)
CensalYear <- c("1970", "1975", "1980", "1990", "1995", "2000", "2007", "2010")
qplot(CensalYear, IliganCity, xlab = expression(bold("Censal Year")),
ylab = expression(bold("Population")), geom = "bar", colour = I("red"),
fill = IliganCity, stat = "identity", ylim = c(0, 370000)) + theme_bw() +
opts(
@raffdoc
raffdoc / pubmed_pain.r
Created May 16, 2012 17:07 — forked from bobthecat/pubmed_pain.r
pubmed trend for pain
source('pubmed_trend.r')
sex.pub <- pubmed_trend(search.str = 'Sex+Characteristics[mh] AND Pain[mh]', year.span=1970:2011)
analgesic.pub <- pubmed_trend(search.str = 'Sex+Characteristics[mh] AND Analgesics[mh]', year.span=1970:2011)
source('plot_bar.r')
library("RColorBrewer")
pdf(file='sex_pain.pdf', height=8, width=8)
par(las=1)
colorfunction = colorRampPalette(brewer.pal(9, "Reds"))