R Markdown

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:

summary(cancer_data)
##        Entity            Code           Year     
##  Length   :6840   Length   :6840   Min.   :1990  
##  N.unique : 228   N.unique : 206   1st Qu.:1997  
##  N.blank  :   0   N.blank  : 690   Median :2004  
##  Min.nchar:   3   Min.nchar:   0   Mean   :2004  
##  Max.nchar:  34   Max.nchar:   8   3rd Qu.:2012  
##                                    Max.   :2019  
##  Deaths...Neoplasms...Sex..Both...Age..Under.5..Number.
##  Min.   :    0                                         
##  1st Qu.:    7                                         
##  Median :   44                                         
##  Mean   : 1473                                         
##  3rd Qu.:  283                                         
##  Max.   :85197                                         
##  Deaths...Neoplasms...Sex..Both...Age..5.14.years..Number.
##  Min.   :    0                                            
##  1st Qu.:   11                                            
##  Median :   64                                            
##  Mean   : 1556                                            
##  3rd Qu.:  286                                            
##  Max.   :71295                                            
##  Deaths...Neoplasms...Sex..Both...Age..15.49.years..Number.
##  Min.   :      0.0                                         
##  1st Qu.:    193.8                                         
##  Median :    939.5                                         
##  Mean   :  25797.3                                         
##  3rd Qu.:   4366.0                                         
##  Max.   :1065003.0                                         
##  Deaths...Neoplasms...Sex..Both...Age..70..years..Number.
##  Min.   :      1                                         
##  1st Qu.:    424                                         
##  Median :   2536                                         
##  Mean   :  95044                                         
##  3rd Qu.:  14236                                         
##  Max.   :4909133                                         
##  Deaths...Neoplasms...Sex..Both...Age..50.69.years..Number.
##  Min.   :      0                                           
##  1st Qu.:    471                                           
##  Median :   2804                                           
##  Mean   :  82983                                           
##  3rd Qu.:  12379                                           
##  Max.   :4006173

Including Plots

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.

library(ggplot2)
library(dplyr)
## 
## 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
ggplot(filter(cancer_data, Year >= 2015 & Year <= 2019), aes(x = Year, y = Deaths...Neoplasms...Sex..Both...Age..70..years..Number.)) +
  geom_point() +
  labs(
    title = "Cancer Deaths (Age 70+) Over Time (2015-2019)",
    x = "Year",
    y = "Number of Deaths"
  )

library(ggplot2)
library(dplyr)

ggplot(filter(cancer_data, Year >= 2015 & Year <= 2019), aes(x = Year, y = Deaths...Neoplasms...Sex..Both...Age..70..years..Number.)) +
  geom_line(stat = "summary", fun = "mean", color = "blue", linewidth = 1) +
  labs(
    title = "Average Cancer Deaths (Age 70+) (2015-2019)",
    x = "Year",
    y = "Average Number of Deaths"
  ) +
  theme_minimal()