DS LAB

#Setup and Libraries 
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.2.1     ✔ readr     2.2.0
✔ forcats   1.0.1     ✔ stringr   1.6.0
✔ ggplot2   4.0.3     ✔ tibble    3.3.1
✔ lubridate 1.9.5     ✔ tidyr     1.3.2
✔ purrr     1.2.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
library(dslabs)
Section 1: Data Overview

I chose to analyze murders dataset from the dslabs package. This package contains 2010 total number of gun murders in state, population in each state, the geographical regions.

My scatterplot graph will investigate the relation between State population and total gun murders bystates in each region .

Section 2: Multivariable grap

 #create multivariable graph
ggplot(data=murders,aes(x=population/10^6,y=total,color=region))+
  #adding points and alpha 
  geom_point(size=3, alpha=0.8)+
  #color palette and legend title
  scale_color_brewer(palette="set1", name="US Region")+
  #changing from default colorto minimal theme 
  theme_minimal(base_size=12)+
  #titles and labels 
  labs(
    title="US Gun Murders vs State Populaton (2010",
    subtitle="Higher state populations correlate with higher total gun murders ",
    x="Population (millions",
    y="Total Gun murders",
    caption="Dslabs data package(murders"
  )
Warning: Unknown palette: "set1"