The methods section for a data-driven research project should describe:
Dividing Lines: full and rather complicated methods section
Housing Affordability: Census-based, simple methods section
R Markdown is a scripting language to create documents that run R scripts, but don’t require R or R Studio to open and view.
R Notebook is an R Markdown document with chunks that can be executed independently and interactively, with output visible immediately beneath the input.
They are excellent tools for collaboration and to publish results.
R Notebook of City Educational Attainment scatterplot
An R Notebook is a document that uses the R Markdown language to create an interactive document that can dsiplay output from R code. It includes formatted text and R code chunks that can be executed independently and interactively, with output visible immediately beneath the input.
Create a new R Notebook File -> New File -> R Notebook
Select the Source
view to type in your text and code - I always work in Source mode
Select the Visual
view to see what your Notebook will look like
Type text directly into the Notebook (we’ll discuss formatting later)
Insert R code into a Notebook in a chunk
Preview
or Knit
as you add elements to your Notebook to see the output in the Viewer pane
Preview
renders your text and any code that has already been runKnit
runs your code, renders all text and code, and displays your Notebook in the Viewer
You can type directly into your R Notebook with regular text. All formatting uses the R Markdown syntax.
To test your R code, click the green arrow within a code chunk to Run it. The output will display below.
Create an R Notebook to publish the Percent West Indian ancestry map
To hide the console messages in your R Notebook, add 2 parameters to your code chunk
message = FALSE
: hides messagesresults='hide'
: hides text outputSee the R Markdown Reference Guide for a complete list of knitr chunk options.
You can add a tooltip to any ggplot to make it interactive using the plotly package.
Install the plotly
package and add it to your script in the packages code chunk:
See the next slides for how to add the tooltip to your map and display it with ggplotly.
west_indian_map
)data
definition and aes()
to the geom_sf()
function in your ggplotaes()
, define the tooltip text in a new text
parameter
paste0()
function to construct it<br>
makes a “break”, to go to a new lineThen, display it with the ggplotly()
function:
Knit to HTML
Assignment 11a
Assignment 11b
OR
OR
In the Notebook, include:
Upload a link to your published R Notebook to Canvas
In the Notebook, include:
Upload a link to your published R Notebook to Canvas