Jorge Cimentada
5th of March of 2016

R is a language and environment for statistical computing and graphics
An effective data handling and storage facility;
A large, coherent, integrated collection of intermediate tools for data analysis;
Graphical facilities for data analysis and display either on-screen or on hardcopy;
Simple and effective programming language which includes conditionals, loops, user-defined recursive functions and input and output facilities.
You have the freedom to run the program as you wish, for any purpose (freedom 0).
You have the freedom to study how the program works, and change it so it does your computing as you wish (freedom 1).
You have the freedom to redistribute copies so you can help your neighbor (freedom 2).
You have the freedom to distribute copies of your modified versions to others (freedom 3).


Adapted from 'R for Stata users' by Muenchen and Hilbe
par(mfrow = c(1, 2))
plot(iris$Sepal.Length, iris$Petal.Length, col = iris$Species, main = "Sepal vs Petal Length in Iris")
plot(iris$Sepal.Length, iris$Sepal.Width, col = iris$Species, main = "Sepal Length vs Width in Iris")
Problem = Explanatory graphs for teaching
*Problem = Showing overlapping variation using Venn diagrams
Problem = Showing relationships between data points
This is among the most recognized graphs in R!
Problem = Nicely formatted barplot with minimum code
library(ggplot2)
ggplot(diamonds, aes(clarity, fill=cut)) + geom_bar()
Problem = Visualizing a bivariate relationship filtered by two variables
library(ggplot2)
qplot(wt, mpg, data=mtcars, size=qsec, color=factor(carb))
Problem = Visualizing a bivariate relationship by a categorical variable
library(ggplot2)
qplot(mpg, wt, data = mtcars, facets = cyl ~ ., geom = c("point", "smooth")) +
coord_flip()
_Problem = Combine existing graphs in a nice format _* **Note: There's some other code going on in the back! Not that easy.
multiplot(p1, p2, p3, p4, cols = 2)
_Problem = Visualizing complex statistical techniques
http://jason.bryer.org/multilevelPSA/
_Problem = Plotting distributions next to scatterplots

Problem = Making nice graphical summaries

Problem = Visualize Likert type questions quickly

_Problem = Exploring your data visually in a fast way _ ** Run this in your R console **
library(openintro)
edaPlot(mtcars)
Problem = Getting QUALITY visualizations with almost no work.
Advantages of ggvis over other graph packages:
For more info, go to ggvis
_Problem = Getting QUALITY visualizations exportable to websites. _ ** Run this on your R console **
library(plotly)
set.seed(100)
d <- diamonds[sample(nrow(diamonds), 1000), ]
plot_ly(d, x = carat, y = price, text = paste("Clarity: ", clarity),
mode = "markers", color = carat, size = carat)
For more see plotly
Let's play around!
library(ggvis)
span <- waggle(0.2,1)
span <- left_right(0.2,1,step = 0.1)
mtcars %>%
ggvis(~mpg, ~disp) %>%
layer_lines() %>%
layer_smooths(span=span)
The first 'span' variable will adjust the smoothness automatically You can adjust the smoothness with your left-right arrow with the second span

Crime density in Baltimore



** Run this in the console **
library(stargazer)
stargazer(mtcars[c("mpg","hp","drat")], type = "text",
title="Descriptive statistics/selected variables", digits=1, out="table2.txt", flip=TRUE,
covariate.labels=c("Miles/(US)gallon","Gross horsepower","Rear axle ratio"))
** Run this in the console **
library(stargazer)
mtcars$fast <- as.numeric((mtcars$mpg > 20.1))
m1 <- lm(mpg ~ hp + drat + factor(gear), data=mtcars)
m2 <- glm(fast ~ hp + drat + am, family=binomial(link="logit"), data=mtcars)
stargazer(m1, m2,type="text", dep.var.labels=c("Miles/(US) gallon","Fast car (=1)"), covariate.labels=c("Gross horsepower","Rear axle ratio","Four foward gears","Five forward gears","Type of transmission (manual=1)"))
Where did you think this presentation was done?
Checkout Rmarkdown and also here
But of course, it's not built to write research papers, it's more for:
There's also slidify
With the swirl package you can program exercises and homeworks that students can do anywhere.
Try it out yourself:
library("swirl")
swirl()