HW5

Beginning to answer the question

Nasko
2022-06-28

Introduction

Electric vehicles are becoming increasingly prevalent in our everyday life. Even though owning a Tesla is still generally perceived as a luxury only a lucky few can afford, the technologies which enable the transition from fossil fuels to renewable energy have marched steadily forward. Nonetheless, challenges to EV ownership have persisted. In this report I examine EV trends present in Washington State, which signed into law a bill setting a date of 2030 for all new cars registered in the state to be electric. I analyze relationships among several important variables and segment the Washington EV market into several zones with their distinct characteristics.

Data Overview

colnames(ev_data)
 [1] "ID"                                               
 [2] "VIN (1-10)"                                       
 [3] "County"                                           
 [4] "City"                                             
 [5] "State"                                            
 [6] "ZIP Code"                                         
 [7] "Model Year"                                       
 [8] "Make"                                             
 [9] "Model"                                            
[10] "Electric Vehicle Type"                            
[11] "Clean Alternative Fuel Vehicle (CAFV) Eligibility"
[12] "Electric Range"                                   
[13] "Base MSRP"                                        
[14] "Legislative District"                             
[15] "DOL Vehicle ID"                                   
[16] "Vehicle Location"                                 
[17] "Electric Utility"                                 
[18] "Expected Price ($1k)"                             
summary(ev_data)
      ID             VIN (1-10)           County         
 Length:64353       Length:64353       Length:64353      
 Class :character   Class :character   Class :character  
 Mode  :character   Mode  :character   Mode  :character  
                                                         
                                                         
                                                         
                                                         
     City              State              ZIP Code       Model Year  
 Length:64353       Length:64353       Min.   :  745   Min.   :1993  
 Class :character   Class :character   1st Qu.:98052   1st Qu.:2017  
 Mode  :character   Mode  :character   Median :98121   Median :2018  
                                       Mean   :98143   Mean   :2018  
                                       3rd Qu.:98370   3rd Qu.:2021  
                                       Max.   :99701   Max.   :2022  
                                       NA's   :6       NA's   :7     
     Make              Model           Electric Vehicle Type
 Length:64353       Length:64353       Length:64353         
 Class :character   Class :character   Class :character     
 Mode  :character   Mode  :character   Mode  :character     
                                                            
                                                            
                                                            
                                                            
 Clean Alternative Fuel Vehicle (CAFV) Eligibility Electric Range 
 Length:64353                                      Min.   :  0.0  
 Class :character                                  1st Qu.: 14.0  
 Mode  :character                                  Median : 73.0  
                                                   Mean   :106.9  
                                                   3rd Qu.:215.0  
                                                   Max.   :337.0  
                                                                  
   Base MSRP      Legislative District DOL Vehicle ID     
 Min.   :     0   Min.   : 0.00        Min.   :     4385  
 1st Qu.:     0   1st Qu.:19.00        1st Qu.:137286488  
 Median :     0   Median :34.00        Median :175377597  
 Mean   :  2525   Mean   :29.95        Mean   :197290491  
 3rd Qu.:     0   3rd Qu.:43.00        3rd Qu.:229903894  
 Max.   :845000   Max.   :49.00        Max.   :478934571  
                  NA's   :169                             
 Vehicle Location   Electric Utility   Expected Price ($1k)
 Length:64353       Length:64353       Min.   :   0.00     
 Class :character   Class :character   1st Qu.:  22.86     
 Mode  :character   Mode  :character   Median :  40.00     
                                       Mean   :  45.45     
                                       3rd Qu.:  65.90     
                                       Max.   :1100.00     
                                       NA's   :13          

VIN (1-10) - The 1st 10 characters of each vehicle’s Vehicle Identification Number (VIN).
County - The county in which the registered owner resides.
City - The city in which the registered owner resides.
State- The state in which the registered owner resides.
ZIP Code - The 5-digit zip code in which the registered owner resides.
Model Year - The model year of the vehicle is determined by decoding the Vehicle Identification Number (VIN).
Make - The manufacturer of the vehicle, determined by decoding the Vehicle Identification Number (VIN).
Model- The model of the vehicle is determined by decoding the Vehicle Identification Number (VIN).
Electric Vehicle Type - This distinguishes the vehicle as all-electric or a plug-in hybrid.
Clean Alternative Fuel Vehicle (CAFV) Eligibility - This categorizes vehicles as Clean Alternative Fuel Vehicles (CAFVs) based on the fuel requirement and electric-only range requirement.
Electric Range - Describes how far a vehicle can travel purely on its electric charge.
Base MSRP - This is the lowest Manufacturer’s Suggested Retail Price (MSRP) for any trim level of the model in question.
Legislative District - The specific section of Washington State that the vehicle’s owner resides in, as represented in the state legislature.
DOL Vehicle ID - Unique number assigned to each vehicle by the Department of Licensing for identification purposes.
Vehicle Location - The center of the ZIP Code for the registered vehicle.
Electric Utility - This is the electric power retail service territory serving the address of the registered vehicle.
Expected Price - This is the expected price of the vehicle.

# Returns the summary statistics of a particular column
print_stats <- function(x) {
  print(paste("Min: ",as.character(min(x, na.rm = TRUE))))
  print(paste("Max: ",as.character(max(x, na.rm = TRUE))))
  print(paste("Median: ",as.character(median(x, na.rm = TRUE))))
  print(paste("Standard Deviation: ",as.character(sd(x, na.rm = TRUE))))
  print(paste("Mean: ",as.character(mean(x, na.rm = TRUE))))
  print(paste("Interquartile Range",as.character(IQR(x, na.rm = TRUE))))
}

#Calculating the summary statistics for the electric range of electric vehicles
el_range_summary_stats <- print_stats(ev_data$`Electric Range`)
[1] "Min:  0"
[1] "Max:  337"
[1] "Median:  73"
[1] "Standard Deviation:  104.093918983571"
[1] "Mean:  106.948984507327"
[1] "Interquartile Range 201"
#Calculating the summary statistics for the expected price of electric vehicles
expected_price_summary_stats <- print_stats(ev_data$`Expected Price ($1k)`)
[1] "Min:  0"
[1] "Max:  1100"
[1] "Median:  40"
[1] "Standard Deviation:  24.7282052168784"
[1] "Mean:  45.4479695679204"
[1] "Interquartile Range 43.043"

The summary statistics tells us that, on average, the range of an electric vehicle in the data is just shy of 75 miles on a single charge. However, the standard deviation of 104 miles tells us that the data is quite a bit dispersed from the mean. The summary statistics of the expected price paint a somewhat different picture. The mean and median are very similar and the standard deviation is only 25000. The max of $1.1M tells us that there are some expensive outliers in the data.

# Calculate frequencies for the following categorical variables: EV Type, Make, Electric Utility and County
table(ev_data$`Electric Vehicle Type`)

        Battery Electric Vehicle (BEV) 
                                 47869 
Plug-in Hybrid Electric Vehicle (PHEV) 
                                 16484 
prop.table(table(ev_data$`Electric Vehicle Type`))

        Battery Electric Vehicle (BEV) 
                             0.7438503 
Plug-in Hybrid Electric Vehicle (PHEV) 
                             0.2561497 
table(ev_data$Make)

                AUDI       AZURE DYNAMICS              BENTLEY 
                1265                    3                    1 
                 BMW             CADILLAC            CHEVROLET 
                2707                   69                 6651 
            CHRYSLER                DODGE                 FIAT 
                1091                    1                  561 
              FISKER                 FORD                HONDA 
                  11                 3850                  528 
             HYUNDAI               JAGUAR                 JEEP 
                 894                  142                  436 
                 KIA           LAND ROVER              LINCOLN 
                3066                   26                   59 
        LUCID MOTORS        MERCEDES-BENZ                 MINI 
                   2                  248                  303 
          MITSUBISHI               NISSAN             POLESTAR 
                 376                 8678                  164 
             PORSCHE               RIVIAN                SMART 
                 455                   26                  192 
              SUBARU                TESLA                TH!NK 
                  34                27903                    1 
              TOYOTA           VOLKSWAGEN                VOLVO 
                2700                 1217                  688 
WHEEGO ELECTRIC CARS 
                   1 
prop.table(table(ev_data$`Electric Utility`))

                                                                                                     AVISTA CORP 
                                                                                                    1.933020e-03 
                                                                       AVISTA CORP||INLAND POWER & LIGHT COMPANY 
                                                                                                    1.571561e-05 
                                                                                 BONNEVILLE POWER ADMINISTRATION 
                                                                                                    3.143122e-05 
                                       BONNEVILLE POWER ADMINISTRATION||AVISTA CORP||BIG BEND ELECTRIC COOP, INC 
                                                                                                    3.300278e-04 
                                      BONNEVILLE POWER ADMINISTRATION||AVISTA CORP||INLAND POWER & LIGHT COMPANY 
                                                                                                    1.436407e-02 
                                         BONNEVILLE POWER ADMINISTRATION||AVISTA CORP||PUD NO 1 OF ASOTIN COUNTY 
                                                                                                    4.557527e-04 
                                                     BONNEVILLE POWER ADMINISTRATION||BENTON RURAL ELECTRIC ASSN 
                                                                                                    5.814776e-04 
                                                    BONNEVILLE POWER ADMINISTRATION||BIG BEND ELECTRIC COOP, INC 
                                                                                                    1.728717e-04 
                                 BONNEVILLE POWER ADMINISTRATION||CITY OF CENTRALIA - (WA)|CITY OF TACOMA - (WA) 
                                                                                                    1.178671e-03 
                                                      BONNEVILLE POWER ADMINISTRATION||CITY OF COULEE DAM - (WA) 
                                                                                                    3.143122e-05 
                                                      BONNEVILLE POWER ADMINISTRATION||CITY OF ELLENSBURG - (WA) 
                                                                                                    6.914869e-04 
                                                        BONNEVILLE POWER ADMINISTRATION||CITY OF MCCLEARY - (WA) 
                                                                                                    1.257249e-04 
                                    BONNEVILLE POWER ADMINISTRATION||CITY OF MILTON - (WA)|CITY OF TACOMA - (WA) 
                                                                                                    4.400371e-04 
                                                    BONNEVILLE POWER ADMINISTRATION||CITY OF PORT ANGELES - (WA) 
                                                                                                    1.540130e-03 
                                                        BONNEVILLE POWER ADMINISTRATION||CITY OF RICHLAND - (WA) 
                                                                                                    5.311876e-03 
      BONNEVILLE POWER ADMINISTRATION||CITY OF TACOMA - (WA)||BENTON RURAL ELECTRIC ASSN|PENINSULA LIGHT COMPANY 
                                                                                                    2.200185e-04 
BONNEVILLE POWER ADMINISTRATION||CITY OF TACOMA - (WA)||ELMHURST MUTUAL POWER & LIGHT CO|PENINSULA LIGHT COMPANY 
                                                                                                    2.184470e-03 
          BONNEVILLE POWER ADMINISTRATION||CITY OF TACOMA - (WA)||LAKEVIEW LIGHT & POWER|PENINSULA LIGHT COMPANY 
                                                                                                    8.486430e-04 
  BONNEVILLE POWER ADMINISTRATION||CITY OF TACOMA - (WA)||OHOP MUTUAL LIGHT COMPANY, INC|PENINSULA LIGHT COMPANY 
                                                                                                    6.757712e-04 
  BONNEVILLE POWER ADMINISTRATION||CITY OF TACOMA - (WA)||PARKLAND LIGHT & WATER COMPANY|PENINSULA LIGHT COMPANY 
                                                                                                    6.286244e-04 
                                 BONNEVILLE POWER ADMINISTRATION||CITY OF TACOMA - (WA)||PENINSULA LIGHT COMPANY 
                                                                                                    4.555955e-02 
                                BONNEVILLE POWER ADMINISTRATION||CITY OF TACOMA - (WA)||PUD NO 1 OF LEWIS COUNTY 
                                                                                                    2.215901e-03 
                                BONNEVILLE POWER ADMINISTRATION||CITY OF TACOMA - (WA)||PUD NO 1 OF MASON COUNTY 
                                                                                                    6.914869e-04 
                                BONNEVILLE POWER ADMINISTRATION||CITY OF TACOMA - (WA)||PUD NO 3 OF MASON COUNTY 
                                                                                                    4.211784e-03 
                                                  BONNEVILLE POWER ADMINISTRATION||COLUMBIA RURAL ELEC ASSN, INC 
                                                                                                    1.571561e-04 
                                                   BONNEVILLE POWER ADMINISTRATION||INLAND POWER & LIGHT COMPANY 
                                                                                                    2.215901e-03 
                                                       BONNEVILLE POWER ADMINISTRATION||ORCAS POWER & LIGHT COOP 
                                                                                                    6.553410e-03 
                                                      BONNEVILLE POWER ADMINISTRATION||PUD 1 OF SNOHOMISH COUNTY 
                                                                                                    8.722164e-03 
                        BONNEVILLE POWER ADMINISTRATION||PUD NO 1 OF ASOTIN COUNTY||INLAND POWER & LIGHT COMPANY 
                                                                                                    3.143122e-05 
                                                      BONNEVILLE POWER ADMINISTRATION||PUD NO 1 OF BENTON COUNTY 
                                                                                                    7.449199e-03 
                                                     BONNEVILLE POWER ADMINISTRATION||PUD NO 1 OF CLALLAM COUNTY 
                                                                                                    5.374739e-03 
                        BONNEVILLE POWER ADMINISTRATION||PUD NO 1 OF CLALLAM COUNTY|PUD NO 1 OF JEFFERSON COUNTY 
                                                                                                    1.571561e-05 
                                                BONNEVILLE POWER ADMINISTRATION||PUD NO 1 OF CLARK COUNTY - (WA) 
                                                                                                    5.921642e-02 
                                                     BONNEVILLE POWER ADMINISTRATION||PUD NO 1 OF COWLITZ COUNTY 
                                                                                                    5.437601e-03 
                                                       BONNEVILLE POWER ADMINISTRATION||PUD NO 1 OF FERRY COUNTY 
                                                                                                    1.414405e-04 
                                                    BONNEVILLE POWER ADMINISTRATION||PUD NO 1 OF FRANKLIN COUNTY 
                                                                                                    2.970250e-03 
                                                BONNEVILLE POWER ADMINISTRATION||PUD NO 1 OF GRAYS HARBOR COUNTY 
                                                                                                    3.551728e-03 
                                                    BONNEVILLE POWER ADMINISTRATION||PUD NO 1 OF KITTITAS COUNTY 
                                                                                                    9.429366e-05 
                                                   BONNEVILLE POWER ADMINISTRATION||PUD NO 1 OF KLICKITAT COUNTY 
                                                                                                    1.492983e-03 
                          BONNEVILLE POWER ADMINISTRATION||PUD NO 1 OF MASON COUNTY|PUD NO 1 OF JEFFERSON COUNTY 
                                                                                                    1.571561e-04 
                                                        BONNEVILLE POWER ADMINISTRATION||PUD NO 1 OF SKAMANIA CO 
                                                                                                    1.021515e-03 
                                                   BONNEVILLE POWER ADMINISTRATION||PUD NO 1 OF WAHKIAKUM COUNTY 
                                                                                                    3.143122e-04 
                                                     BONNEVILLE POWER ADMINISTRATION||PUD NO 2 OF PACIFIC COUNTY 
                                                                                                    1.540130e-03 
                           BONNEVILLE POWER ADMINISTRATION||PUGET SOUND ENERGY INC||PUD NO 1 OF JEFFERSON COUNTY 
                                                                                                    6.113372e-03 
                                BONNEVILLE POWER ADMINISTRATION||TOWN OF EATONVILLE - (WA)|CITY OF TACOMA - (WA) 
                                                                                                    1.885873e-04 
           BONNEVILLE POWER ADMINISTRATION||TOWN OF RUSTON - (WA)|CITY OF TACOMA - (WA)||PENINSULA LIGHT COMPANY 
                                                                                                    2.357342e-04 
              BONNEVILLE POWER ADMINISTRATION||TOWN OF STEILACOOM|CITY OF TACOMA - (WA)||PENINSULA LIGHT COMPANY 
                                                                                                    1.052946e-03 
                                                   BONNEVILLE POWER ADMINISTRATION||VERA IRRIGATION DISTRICT #15 
                                                                                                    2.027314e-03 
                                                               CITY OF BLAINE - (WA)||PUD NO 1 OF WHATCOM COUNTY 
                                                                                                    1.257249e-03 
                                                                                           CITY OF CHENEY - (WA) 
                                                                                                    2.357342e-04 
                                                                                                CITY OF CHEWELAH 
                                                                                                    6.286244e-05 
                                                                                          CITY OF SEATTLE - (WA) 
                                                                                                    1.571561e-05 
                                                                    CITY OF SEATTLE - (WA)|CITY OF TACOMA - (WA) 
                                                                                                    1.966651e-01 
                                                                CITY OF SUMAS - (WA)||PUD NO 1 OF WHATCOM COUNTY 
                                                                                                    4.714683e-05 
                                                                                           CITY OF TACOMA - (WA) 
                                                                                                    4.714683e-05 
                                                                     CITY OF TACOMA - (WA)||TANNER ELECTRIC COOP 
                                                                                                    1.304396e-03 
                                                                                   MODERN ELECTRIC WATER COMPANY 
                                                                                                    6.537694e-03 
                                                                                  OKANOGAN COUNTY ELEC COOP, INC 
                                                                                                    7.386337e-04 
                                                                                    PORTLAND GENERAL ELECTRIC CO 
                                                                                                    6.286244e-05 
                                                                                       PUD NO 1 OF CHELAN COUNTY 
                                                                                                    5.940501e-03 
                                                                                      PUD NO 1 OF DOUGLAS COUNTY 
                                                                                                    1.933020e-03 
                                                                                     PUD NO 1 OF OKANOGAN COUNTY 
                                                                                                    5.343308e-04 
                                                                                 PUD NO 1 OF PEND OREILLE COUNTY 
                                                                                                    2.985966e-04 
                                                                                      PUD NO 1 OF WHATCOM COUNTY 
                                                                                                    3.614590e-04 
                                                                                        PUD NO 2 OF GRANT COUNTY 
                                                                                                    2.703085e-03 
                                                                                          PUGET SOUND ENERGY INC 
                                                                                                    2.010027e-01 
                                                                   PUGET SOUND ENERGY INC||CITY OF TACOMA - (WA) 
                                                                                                    3.544656e-01 
                                                              PUGET SOUND ENERGY INC||PUD NO 1 OF WHATCOM COUNTY 
                                                                                                    2.527070e-02 
table(ev_data$County)

               Adams              Alameda            Albemarle 
                  21                    1                    1 
     Alexandria City            Allegheny            Anchorage 
                   3                    1                    1 
        Anne Arundel               Asotin            Baltimore 
                   5                   31                    1 
              Bartow                 Bell               Benton 
                   1                    1                  812 
               Bexar              Bradley              Calvert 
                   3                    1                    2 
              Camden              Carroll          Carson City 
                   1                    1                    1 
             Charles               Chaves               Chelan 
                   2                    1                  378 
     Chesapeake City              Clallam                Clark 
                   2                  441                 3771 
            Columbia              Coryell              Cowlitz 
                   7                    1                  346 
          Cumberland        Danville City             Davidson 
                   2                    1                    1 
              Denton District Of Columbia              Douglas 
                   1                    3                  127 
              Dupage                Duval              El Paso 
                   1                    1                    1 
                Erie Fairbanks North Star              Fairfax 
                   1                    1                    5 
               Ferry             Flathead             Franklin 
                  16                    1                  201 
           Frederick             Garfield              Glacier 
                   3                    3                    1 
           Goochland                Grant         Grays Harbor 
                   2                  172                  234 
           Guadalupe             Hamilton               Harris 
                   1                    1                    1 
            Harrison         Hillsborough             Honolulu 
                   1                    1                    4 
              Howard               Hudson              Humacao 
                   2                    1                    1 
              Island            Jefferson                 Kern 
                 773                  400                    2 
                King                Kings               Kitsap 
               33552                    2                 2302 
            Kittitas              Klamath            Klickitat 
                 213                    1                   95 
                Lake              Laramie          Leavenworth 
                   1                    1                    1 
               Lewis              Liberty              Lincoln 
                 293                    1                   17 
         Los Angeles             Maricopa                Marin 
                   4                    1                    1 
               Mason          Mecklenburg             Monterey 
                 325                    1                    1 
          Montgomery            Multnomah             Muscogee 
                   7                    3                    1 
          New Castle           New London              Newport 
                   1                    3                    1 
        Norfolk City               Nueces             Okanogan 
                   1                    1                   82 
              Orange                Otero              Ozaukee 
                   4                    1                    1 
             Pacific              Passaic         Pend Oreille 
                  98                    1                   19 
          Pennington         Philadelphia               Pierce 
                   1                    1                 4825 
            Pinellas               Placer          Plaquemines 
                   1                    1                    1 
              Platte             Powhatan       Prince Georges 
                   1                    1                    1 
      Prince William               Queens                Riley 
                   3                    1                    1 
           Riverside          Rock Island           Sacramento 
                   2                    1                    1 
         Saint Clair          Saint Marys            Salt Lake 
                   1                    1                    1 
      San Bernardino            San Diego             San Juan 
                   2                   16                  419 
         Santa Clara           Santa Cruz             Sarasota 
                   2                    1                    1 
               Sarpy               Skagit             Skamania 
                   1                  779                   65 
           Snohomish              Spokane             Stafford 
                6920                 1579                    1 
             Stevens              Suffolk             Thurston 
                  70                    2                 2446 
              Tipton              Ventura  Virginia Beach City 
                   1                    2                    1 
           Wahkiakum                 Wake          Walla Walla 
                  20                    1                  173 
              Washoe              Whatcom              Whitman 
                   1                 1714                   95 
             Wichita               Wilson               Yakima 
                   1                    1                  350 
             Yamhill 
                   1 

Battery electric vehicles outnumber Plug-in Hybrids in the dataset by almost 3 to 1. This is interesting observation, especially given that PHEVs tend to have smaller batteries and have lower upfront cost. This may indicate that the owners represented here are investing for the long haul with their EV purchase.

# Display EV type proportions per category
ev_data %>%
  count(`Electric Vehicle Type`) %>%
  mutate(perc = n / nrow(ev_data)) -> ev_type_percent
ggplot(data=ev_type_percent, aes(x=`Electric Vehicle Type`, y=perc)) +
  geom_bar(stat="identity") +
  scale_x_discrete(name ="Electric Vehicle Type Breakdown") +
  scale_y_continuous(name ="Percent")
# Plot the summary statistics of electric range and expected price using a boxplot
# Examine the two variables individually as well as their relationship using a scatter plot
ggplot(data=ev_data, aes(x=`Electric Range`)) +
  geom_boxplot(outlier.colour="black", outlier.shape=8,
             outlier.size=2, notch=FALSE) +
  scale_x_continuous(name ="Electric range (miles)", breaks=seq(0,350,50)) +
  theme(axis.text.y = element_blank())
ggplot(data=ev_data, aes(x=`Expected Price ($1k)`)) +
  geom_boxplot(outlier.colour="blue", outlier.shape=8,
             outlier.size=2, notch=FALSE) +
    scale_x_continuous(name ="Expected price (thousands)", limits=c(0,300), breaks=seq(0,300,50)) +
  theme(axis.text.y = element_blank())
ggplot(data=ev_data, aes(x=`Electric Range`, y=`Expected Price ($1k)`)) +
  geom_point(outlier.colour="blue", outlier.shape=8,
             outlier.size=2, notch=FALSE) +
  scale_x_continuous(name="Electric range (miles)",breaks=seq(0,350,50)) +
  scale_y_continuous(name="Expected price (thousands)",limits=c(0,200),breaks=seq(0,200,50))

# Focus solely on Washington States as the dataset focuses predominantly on it
evs_under_30k <- ev_data %>% filter(State == 'WA' & `Expected Price ($1k)` < 30) %>% select(`ZIP Code`, Make, Model, `Electric Vehicle Type`, `Electric Range`, `Expected Price ($1k)`)
# Get stats for Teslas as a luxury brand
teslas <- ev_data %>% filter(Make == "TESLA") %>% select(`ZIP Code`, Make, Model, `Electric Vehicle Type`, `Electric Range`, `Expected Price ($1k)`)

# Get summary statistics for the electric range of EVs under 30k
evs_under_30k %>% summarize(mean.el_range   = mean(`Electric Range`, na.rm = TRUE),
                                     median.el_range = median(`Electric Range`, na.rm = TRUE),
                                     sd.el_range = sd(`Electric Range`, na.rm = TRUE),
                                     min.el_range = min(`Electric Range`, na.rm= TRUE),
                                     max.el_range = max(`Electric Range`, na.rm= TRUE))
# A tibble: 1 × 5
  mean.el_range median.el_range sd.el_range min.el_range max.el_range
          <dbl>           <dbl>       <dbl>        <dbl>        <dbl>
1          72.7              72        62.3            0          258
teslas %>% summarize(mean.el_range   = mean(`Electric Range`, na.rm = TRUE),
                                     median.el_range = median(`Electric Range`, na.rm = TRUE),
                                     sd.el_range = sd(`Electric Range`, na.rm = TRUE),
                                     min.el_range = min(`Electric Range`, na.rm= TRUE),
                                     max.el_range = max(`Electric Range`, na.rm= TRUE))
# A tibble: 1 × 5
  mean.el_range median.el_range sd.el_range min.el_range max.el_range
          <dbl>           <dbl>       <dbl>        <dbl>        <dbl>
1          153.             210        119.            0          337
range.p1 <- lm(`Expected Price ($1k)`~`Electric Range`, data=evs_under_30k)
summary(range.p1)

Call:
lm(formula = `Expected Price ($1k)` ~ `Electric Range`, data = evs_under_30k)

Residuals:
     Min       1Q   Median       3Q      Max 
-20.5998  -2.5466  -0.5566   4.4120   9.3982 

Coefficients:
                   Estimate Std. Error t value Pr(>|t|)    
(Intercept)      20.5998193  0.0481087 428.194   <2e-16 ***
`Electric Range` -0.0007397  0.0005025  -1.472    0.141    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 4.731 on 22808 degrees of freedom
Multiple R-squared:  9.501e-05, Adjusted R-squared:  5.117e-05 
F-statistic: 2.167 on 1 and 22808 DF,  p-value: 0.141
plot(evs_under_30k$`Electric Range`, evs_under_30k$`Expected Price ($1k)`)
abline(range.p1)
evs_under_30k %>% 
  ggplot(aes(`Electric Range`, `Expected Price ($1k)`)) +
  geom_point()
pred <- predict(range.p1)
evs_under_30k %>% ggplot(mapping=aes(x=`Electric Range`)) +
  geom_point(aes(y=`Expected Price ($1k)`)) +
  geom_jitter(aes(y=pred), color="red")

The linear regression shows us that there is no statistically significant relationship between the Electric Range of an EVs under $30k and their expected price (p-value: 14%).

evs_rich_zips <- ev_data %>% 
  filter(City == "REDMOND" | City == 'SEATTLE' | City == 'BELLEVUE' | City == 'MEDINA') %>% #
  select(`ZIP Code`, City, Make, Model, `Electric Vehicle Type`, `Electric Range`, `Expected Price ($1k)`)

range.p2 <- lm(`Expected Price ($1k)`~`Electric Range`, data=evs_rich_zips)
evs_rich_zips %>% 
  ggplot(aes(`Electric Range`, `Expected Price ($1k)`)) +
  geom_point()
#Univariate barplot showing the tpye of EVs in Washington's most expensive cities
ggplot(data=evs_rich_zips, aes(x=`Electric Vehicle Type`)) +
  geom_bar() + 
  theme_clean()
#Bivariate plot telling us which EV makes are present in each of the 4 wealthier cities
ggplot(data=evs_rich_zips, aes(x=City, y=Make)) +
  geom_point()
#Bivariate plot giving an overview of the electric range of EVs in the high-end cities
ggplot(data=evs_rich_zips, aes(x=`Electric Range`,y=Make)) +
  geom_point() +
  scale_x_continuous(name="Electric range (miles)",breaks=seq(0,350,50))

Identifying limitations

This dataset focuses predominantly on EVs in Washington State. Source
While giving a high overview of the data, these visualizations may need further breakdown to convey deeper meaning. For instance, performing more thorough analysis on the zip codes or cities to provide a better understanding of the specific models preferred by those populations may offer an insight into that particular market and would allow a third party (an EV marketing agency, car manufacturers, etc.) to achieve better product placement. In the next iteration I will work on segmenting the data into more easily digestible parts in order to improve the visualizations.