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. You can embed an R code chunk like this:
# install R packages
# install.packages("knitr")
# install.packages("readr")
# install.packages("rmarkdown")
# install.packages("tidyverse")
# Load R libraries
library(knitr)
library(readr)
## Warning: package 'readr' was built under R version 3.6.3
library(rmarkdown)
## Warning: package 'rmarkdown' was built under R version 3.6.3
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 3.6.3
## -- Attaching packages ------------------------------------------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.2.1 v dplyr 0.8.3
## v tibble 3.0.1 v stringr 1.4.0
## v tidyr 1.1.0 v forcats 0.4.0
## v purrr 0.3.4
## Warning: package 'tibble' was built under R version 3.6.3
## Warning: package 'tidyr' was built under R version 3.6.3
## Warning: package 'purrr' was built under R version 3.6.3
## -- Conflicts ---------------------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
# Set working directory
setwd("C:/Users/Wendy/Desktop/ABC Careers/Data Journalist/Viz")
data <- read.csv("Homeless_by_Sex2.csv",header = TRUE)
# View dataframe
glimpse(data)
## Rows: 6
## Columns: 3
## $ Year <int> 2006, 2006, 2011, 2011, 2016, 2016
## $ Sex <fct> Male, Female, Male, Female, Male, Female
## $ Homeless <int> 51159, 38569, 57689, 44746, 67407, 49017
# Exploratory Data Analysis - Facet Wrap
ggplot(data, aes(Year,Homeless)) +
geom_line(aes(colour = Sex)) +
facet_wrap(~Sex, scales ="free", ncol = 1) +
theme(strip.text.y = element_text(angle = 0)) +
ggtitle("Homelessness in Australia by Gender (2006-2016), Source: ABS")
ggplot(data, aes(Year,Homeless)) +
geom_line(aes(colour = Sex)) +
facet_wrap(~Sex) +
ggtitle("Homelessness in Australia by Gender (2006-2016), Source: ABS")
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.