DSLabs- ACM

Author

Andrew Marshall

#Choosing Us Contagious Diseases from the DS Labs. #Read in the file

library(tidyverse)
Warning: package 'tidyr' was built under R version 4.3.3
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.4.4     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
data(package="dslabs")

#breakdown data for graphing

US_Cont <- read_csv("us_contagious_diseases.csv")
Rows: 16065 Columns: 6
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (2): disease, state
dbl (4): year, weeks_reporting, count, population

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
US_Cont1 <- US_Cont|>
  filter(disease == "Measles", state == "Maryland")|>
  group_by(year)|>
  head(13)
US_Cont1
# A tibble: 13 × 6
# Groups:   year [13]
   disease state     year weeks_reporting count population
   <chr>   <chr>    <dbl>           <dbl> <dbl>      <dbl>
 1 Measles Maryland  1928              52 17539    1598519
 2 Measles Maryland  1929              52  2043    1615468
 3 Measles Maryland  1930              50  1209    1631526
 4 Measles Maryland  1931              51 20959    1646632
 5 Measles Maryland  1932              51  1093    1661162
 6 Measles Maryland  1933              52   697    1675618
 7 Measles Maryland  1934              52 26948    1690521
 8 Measles Maryland  1935              52  2302    1706409
 9 Measles Maryland  1936              50  7073    1723842
10 Measles Maryland  1937              50 12246    1743406
11 Measles Maryland  1938              52  2813    1765716
12 Measles Maryland  1939              51 15295    1791427
13 Measles Maryland  1940              48  4305    1821244

#Graph

library(treemap)
Warning: package 'treemap' was built under R version 4.3.3
graph1 <- US_Cont1 |>
  treemap(index="year", vSize="population", vColor="count",          type="manual",palette="RdYlBu")

  graph1
$tm
   year   vSize vColor  stdErr vColorValue level        x0        y0         w
1  1928 1598519  17539 1598519       17539     1 0.7416218 0.0000000 0.2583782
2  1929 1615468   2043 1615468        2043     1 0.7416218 0.2803047 0.2583782
3  1930 1631526   1209 1631526        1209     1 0.4780848 0.0000000 0.2635370
4  1931 1646632  20959 1646632       20959     1 0.4780848 0.2804922 0.2635370
5  1932 1661162   1093 1661162        1093     1 0.8275445 0.5635814 0.1724555
6  1933 1675618    697 1675618         697     1 0.6535882 0.5635814 0.1739563
7  1934 1690521  26948 1690521       26948     1 0.4780848 0.5635814 0.1755034
8  1935 1706409   2302 1706409        2302     1 0.2436803 0.0000000 0.2344045
9  1936 1723842   7073 1723842        7073     1 0.2436803 0.3298265 0.2344045
10 1937 1743406  12246 1743406       12246     1 0.2436803 0.6630225 0.2344045
11 1938 1765716   2813 1765716        2813     1 0.0000000 0.0000000 0.2436803
12 1939 1791427  15295 1791427       15295     1 0.0000000 0.3282984 0.2436803
13 1940 1821244   4305 1821244        4305     1 0.0000000 0.6613773 0.2436803
           h   color
1  0.2803047 #CAE8F2
2  0.2832767 #BE1826
3  0.2804922 #AA0426
4  0.2830892 #84BAD8
5  0.4364186 #AA0426
6  0.4364186 #A50026
7  0.4364186 #313695
8  0.3298265 #C31C26
9  0.3331960 #F7864E
10 0.3369775 #FEE99E
11 0.3282984 #CD2626
12 0.3330789 #EFF9DB
13 0.3386227 #DF422F

$type
[1] "manual"

$vSize
[1] "population"

$vColor
[1] "count"

$stdErr
[1] "population"

$algorithm
[1] "pivotSize"

$vpCoorX
[1] 0.02812148 0.97187852

$vpCoorY
[1] 0.171685 0.910315

$aspRatio
[1] 1.788798

$range
[1]     0 25000

$mapping
[1] NA NA NA

$draw
[1] TRUE