An illustration of R Markdown….
What’s the link between foreigners and crime?
Now let’s load some data. To do that you can include chunks of are code like this:
ff=read.csv("https://www.dropbox.com/s/g1w75gkw7g91zef/foreigners.csv?dl=1")
This loads the local authority dataset we have seen before. Note that you can include inline are code as well. For instance: the dataset has 348 observations and contains 5 variables.
As before we can summarise the data:
summary(ff)
## X crimes11 b_migr11 pop11
## Min. : 1.00 Min. : 1134 Min. : 2.241 Min. : 2203
## 1st Qu.: 87.75 1st Qu.: 107618 1st Qu.: 4.899 1st Qu.: 94263
## Median :174.50 Median : 160556 Median : 7.603 Median : 125746
## Mean :174.50 Mean : 236988 Mean :11.226 Mean : 161434
## 3rd Qu.:261.25 3rd Qu.: 309377 3rd Qu.:12.382 3rd Qu.: 200247
## Max. :348.00 Max. :1714295 Max. :55.161 Max. :1072372
## NA's :24 NA's :9 NA's :9
## area
## : 9
## Adur : 1
## Allerdale : 1
## Amber Valley: 1
## Arun : 1
## Ashfield : 1
## (Other) :334
Note, you might want to see the output of a command in your final document, but you might not want to see the command. Just do it like this:
## X crimes11 b_migr11 pop11
## Min. : 1.00 Min. : 1134 Min. : 2.241 Min. : 2203
## 1st Qu.: 87.75 1st Qu.: 107618 1st Qu.: 4.899 1st Qu.: 94263
## Median :174.50 Median : 160556 Median : 7.603 Median : 125746
## Mean :174.50 Mean : 236988 Mean :11.226 Mean : 161434
## 3rd Qu.:261.25 3rd Qu.: 309377 3rd Qu.:12.382 3rd Qu.: 200247
## Max. :348.00 Max. :1714295 Max. :55.161 Max. :1072372
## NA's :24 NA's :9 NA's :9
## area
## : 9
## Adur : 1
## Allerdale : 1
## Amber Valley: 1
## Arun : 1
## Ashfield : 1
## (Other) :334
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
## Warning: Removed 24 rows containing missing values (geom_point).
Let’s get rid of outliers… …and do some other stuff to make it look nicer..