Problem 1

For a data set of your choosing, make a faceted plot using the trelliscopejs package. You may make any type of plot; scatter plot, histogram, etc. but, as mentioned in the discussion below, you must explain why you chose this plot and what you are investigating about the variable you are graphing.

The trelliscope plot must include one cognostic measure of your own. Include a description of what it is and what information this measure gives.

library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.5.2
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
library(gapminder)
## Warning: package 'gapminder' was built under R version 4.5.2
library(trelliscopejs)
## Warning: package 'trelliscopejs' was built under R version 4.5.2
## This package is no longer maintained. Please use the 'trelliscope' package instead (see https://github.com/trelliscope/).
bmw_data <- read.csv("C:/Temp/Bmw_Dataset.csv")

bmw_data_transformed <- bmw_data %>%
                        filter(!fuelType %in% c("Other", "Electric")) %>%                  
                        group_by(year, model, fuelType ) %>%
                        summarise(mean_mpg = mean(mpg))
## `summarise()` has grouped output by 'year', 'model'. You can override using the
## `.groups` argument.
bmw_data_transformed$mean_mpg <- cog(bmw_data_transformed$mean_mpg, desc = "Mean for MPG")

output_dir <- "." 

plot <- ggplot(bmw_data_transformed, aes(year,mean_mpg)) +
        geom_line() +
        labs(x = "Year",
             y = "Average MPG") +
        facet_trelliscope(~ model + fuelType,
                          name = "Model and Fuel Type",
                          desc = "Average MPG by Year",
                          nrow = 2, ncol = 2,                  
                          scales = c("same", "sliced"),
                          self_contained = TRUE,
                          path = output_dir)

plot
## using data from the first layer
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?

Description 2-3 paragraphs.

Describe the data set. Explain the variable you are graphing in your plots and the reason you are investigating with it. Discuss the reason/motivation you chose the variable to facet on, and what insight or trend you are attempting to investigate. Discuss any challenges you had in making the graphs and how you dealt with these challenges. Name at least one cognostic measure (this can include the cognostic you created or be different) the reader could investigate, and explain any insight they might gain from it.

Description

The data set that was utilized for this assignment is one that contains information on over 10,000 BMW vehicles. The data set contains information such as model, year, cost, price, and mileage. The specific data elements which I chose for this assignment are model, fuel type, mpg, and year. To elaborate, year refers to when the car was built and mpg refers to the average miles per gallon over the specific cars lifetime.

I chose these variables because I was interested in understanding whether BMW vehicle models, based on their fuel type, see an increase in miles per gallon in newer year versions. The main challenge that I had when producing the graphs was ensuring that the data included enabled accurate insights to be gained. One example of that is the fuel type of “Other” did not have many data points, thus making it impossible to accurately evaluate potential trends. To solve this issue, I removed records related to the “Other” fuel type. Additionally, there were rows that had fuel type of “Electric” that had mpg assignments. I removed these values as well to avoid confusion.

Lastly, one cognostic measure that an individual could investigate is the Mean Mpg Max. This cognostic would enable a reader to determine which Model, Fuel Type, and Year has the highest Miles Per Gallon on average. This could help them understand which vehicles get the best mpg when attempting to buy used BMW vehicle.

Link to RPub: https://rpubs.com/cajst9/Assignment_4