This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document.
The R-markdown definitie guide jsut came out! check it here.
Chek out also the cheat sheet here.
You can find the R-markdown document that can be used to produce this html file here
Lets try it now!
We generate a chunk with our normal R code
library(WDI)
## Loading required package: RJSONIO
library(plotly)
## Loading required package: ggplot2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(stargazer)
##
## Please cite as:
## Hlavac, Marek (2018). stargazer: Well-Formatted Regression and Summary Statistics Tables.
## R package version 5.2.1. https://CRAN.R-project.org/package=stargazer
start_year=2008
end_year=2011
worlDIndic=WDI(country = "all", indicator=c("SP.DYN.LE00.IN","NY.GDP.PCAP.CD"),
start = start_year, end = end_year, extra = FALSE, cache = NULL)
#names(worlDIndic)[names(worlDIndic)=="SI.POV.DDAY"]="Poverty %"
names(worlDIndic)[names(worlDIndic)=="SP.DYN.LE00.IN"]="LifeExpectancy"
names(worlDIndic)[names(worlDIndic)=="NY.GDP.PCAP.CD"]="GDPperCapita"
We can visualise the first rows of the data.frame
head(worlDIndic)
plot_ly(worlDIndic, x = ~GDPperCapita, y = ~LifeExpectancy,
size = ~GDPperCapita, text = ~paste("Country: ", country))
## No trace type specified:
## Based on info supplied, a 'scatter' trace seems appropriate.
## Read more about this trace type -> https://plot.ly/r/reference/#scatter
## No scatter mode specifed:
## Setting the mode to markers
## Read more about this attribute -> https://plot.ly/r/reference/#scatter-mode
## Warning: Ignoring 107 observations
The start and end year of this plot is 2008 and 2011 respectively.
There are 3 different ways to visualise tables in markdown. Can you find these in the cheatsheet? Which one are we using here?
simple_model = lm(LifeExpectancy ~ GDPperCapita,worlDIndic)
title = "Linear Relation between GDP per Capita and Life expectancy"
table = stargazer(simple_model, type="html", report=('vc*p'),column.labels=c("Dependent Variable"), dep.var.caption = title, dep.var.labels.include = TRUE,model.names=FALSE, align=TRUE, column.sep.width = "5000pt")
| Linear Relation between GDP per Capita and Life expectancy | |
| LifeExpectancy | |
| Dependent Variable | |
| GDPperCapita | 0.0002*** |
| p = 0.000 | |
| Constant | 66.637*** |
| p = 0.000 | |
| Observations | 949 |
| R2 | 0.361 |
| Adjusted R2 | 0.360 |
| Residual Std. Error | 6.709 (df = 947) |
| F Statistic | 534.589*** (df = 1; 947) |
| Note: | p<0.1; p<0.05; p<0.01 |
Sometimes it is usefull to show the code that you used to generate a plot or a statistical test. However, sometimes you might want to generate a report with only the results. Fear not! We can also do this…
| Linear Relation between GDP per Capita and Life expectancy | |
| LifeExpectancy | |
| Dependent Variable | |
| GDPperCapita | 0.0002*** |
| p = 0.000 | |
| Constant | 66.637*** |
| p = 0.000 | |
| Observations | 949 |
| R2 | 0.361 |
| Adjusted R2 | 0.360 |
| Residual Std. Error | 6.709 (df = 947) |
| F Statistic | 534.589*** (df = 1; 947) |
| Note: | p<0.1; p<0.05; p<0.01 |
XKCD comic XKCD comic
getXKCD(which = "random")
## $month
## [1] "4"
##
## $num
## [1] 1351
##
## $link
## [1] ""
##
## $year
## [1] "2014"
##
## $news
## [1] ""
##
## $safe_title
## [1] "Metamaterials"
##
## $transcript
## [1] "[[A pair of violets, colored red.]]\nViolets are red\n\n[[A blue rose.]]\nAnd roses are blue\n\n[[Two people stand on a stage. Between them is a table, on which rests the two flowers under a translucent cover. One is at a podium with a microphone.]]\nPerson 1: When metamaterials\n\n[[The person at the microphone removes the cover to reveal the flowers are the opposite colors.]]\nPerson 1: Alter their hue.\n\n{{Title text: If I developed a hue-shifting metamaterial, I would photobomb people's Instagram pics with a sheet of material that precisely undid the filter they were using.}}"
##
## $alt
## [1] "If I developed a hue-shifting metamaterial, I would photobomb people's Instagram pics with a sheet of material that precisely undid the filter they were using."
##
## $img
## [1] "https://imgs.xkcd.com/comics/metamaterials.png"
##
## $title
## [1] "Metamaterials"
##
## $day
## [1] "4"
##
## attr(,"class")
## [1] "rxkcd"