This report is Project 2 for MKTG3P98
getwd()
## [1] "/Users/charlesmba/Desktop"
setwd("/Users/charlesmba")
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(ggplot2)
New_Car_Total <- read.csv("/Users/charlesmba/Desktop/New_Car_Total.csv")
Chrysler_models <- c( "Chrysler Jeep")
Ford_models <- c( "Ford Expedition", "Ford Explorer")
toyota_models <- c( "Toyota Corolla", "Toyota Rav4", "Toyota Highlander")
selected_models <- c(Ford_models, toyota_models, Chrysler_models)
filtered_data <- New_Car_Total %>%
filter(Model %in% selected_models)
regions <- c("European", "Asian", "American", "Middle eastern")
region_data <- lapply(regions, function(region) {
filtered_data %>% filter(Region == region)
})
names(region_data) <- regions
mpg_data <- lapply(region_data, function(data) {
data %>%
select(Region, Model, MPG) %>%
filter(!is.na(MPG))
})
mpg_df <- do.call(rbind, mpg_data)
ggplot(mpg_df, aes(x = Region, y = MPG, color = Model)) +
geom_point(position = position_jitter(width = 0.2, height = 0), size = 3, alpha = 0.7) +
labs(title = "MPG Distribution by Region",
x = "Region",
y = "MPG") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
mean_valu_percp <- lapply(region_data, function(data) {
if(nrow(data) > 0) {
data %>%
group_by(Model) %>%
summarise(Mean_Valu_Percp_1 = mean(Valu_Percp_1, na.rm = TRUE))
} else {
data.frame(Model = character(), Mean_Valu_Percp_1 = numeric())
}
})
mean_valu_percp_df <- do.call(rbind, lapply(names(mean_valu_percp), function(region) {
data <- mean_valu_percp[[region]]
if(nrow(data) > 0) {
data.frame(Region = region, data)
} else {
data.frame(Region = character(), Model = character(), Mean_Valu_Percp_1 = numeric())
}
}))
ggplot(mean_valu_percp_df, aes(x = Region, y = Mean_Valu_Percp_1, fill = Model)) +
geom_bar(stat = "identity", position = position_dodge()) +
labs(title = "Mean Value Perception by Region and Car Model",
x = "Region",
y = "Mean Value Perception (1 to 10)") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
chrysler_data <- New_Car_Total %>%
filter(grepl("Chrysler", Model))
regions2 <- c("European", "Asian", "American", "Middle eastern")
region_data2 <- lapply(regions, function(region) {
chrysler_data %>% filter(Region == region)
})
names(region_data) <- regions
pay_meth_counts <- lapply(region_data, function(data) {
table(factor(data$Pay_Meth, levels = 1:3), useNA = "ifany")
})
pay_meth_df <- do.call(rbind, lapply(names(pay_meth_counts), function(region) {
counts <- pay_meth_counts[[region]]
data.frame(Region = region, Pay_Meth = as.numeric(names(counts)), Count = as.vector(counts))
}))
ggplot(pay_meth_df, aes(x = Pay_Meth, y = Count, fill = Region)) +
geom_bar(stat = "identity", position = "dodge") +
labs(title = "Regional Payment Method Distribution (Chryslers)",
x = "Payment Method",
y = "Count") +
theme_minimal()
Age_counts <- lapply(region_data, function(data) {
table(factor(data$Age, levels = 18:60), useNA = "ifany")
})
Age_df <- do.call(rbind, lapply(names(Age_counts), function(region) {
counts <- Age_counts[[region]]
data.frame(Region = region, Pay_Meth = as.numeric(names(counts)), Count = as.vector(counts))
}))
ggplot(Age_df, aes(x = Pay_Meth, y = Count, fill = Region)) +
geom_bar(stat = "identity", position = "dodge") +
labs(title = "Regional Age Distribution for Chrysler Cars",
x = "Age",
y = "Count") +
theme_minimal()
chrysler_data$Enj_mean <- (chrysler_data$Enj_1 + chrysler_data$Enj_2) / 2
chrysler_data$Futu_Pur_mean <- (chrysler_data$Futu_Pur_1 + chrysler_data$Futu_Pur_2) / 2
chrysler_data$WOM_mean <- (chrysler_data$WOM_1 + chrysler_data$WOM_2) / 2
chrysler_data$Valu_Percp_mean <- (chrysler_data$Valu_Percp_1 + chrysler_data$Valu_Percp_2) / 2
ggplot(chrysler_data, aes(x = Enj_mean, y = Futu_Pur_mean)) +
geom_point() +
geom_smooth(method = "lm", col = "blue") +
labs(title = "Correlation between Enjoyment and Future Purchase",
x = "Mean Enjoyment",
y = "Mean Future Purchase") +
theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'
ggplot(chrysler_data, aes(x = Enj_mean, y = WOM_mean)) +
geom_point() +
geom_smooth(method = "lm", col = "blue") +
labs(title = "Correlation between Enjoyment and Word of Mouth",
x = "Mean Enjoyment",
y = "Mean Word of Mouth") +
theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'
ggplot(chrysler_data, aes(x = Futu_Pur_mean, y = Valu_Percp_mean)) +
geom_point() +
geom_smooth(method = "lm", col = "blue") +
labs(title = "Correlation between Future Purchase and Value Perception",
x = "Mean Future Purchase",
y = "Mean Value Perception") +
theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'
ggplot(chrysler_data, aes(x = Enj_mean, y = Futu_Pur_mean)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE, color = "blue") +
facet_wrap(~ Region) +
labs(title = "Correlation between Enjoyment and Future Purchase by Region",
x = "Mean Enjoyment",
y = "Mean Future Purchase") +
theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'
ggplot(chrysler_data, aes(x = Enj_mean, y = WOM_mean)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE, color = "blue") +
facet_wrap(~ Region) +
labs(title = "Correlation between Enjoyment and Word of Mouth by Region",
x = "Mean Enjoyment",
y = "Mean Word of Mouth") +
theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'
ggplot(chrysler_data, aes(x = Futu_Pur_mean, y = Valu_Percp_mean)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE, color = "blue") +
facet_wrap(~ Region) +
labs(title = "Correlation between Future Purchase and Value Perception by Region",
x = "Mean Future Purchase",
y = "Mean Value Perception") +
theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'
ggplot(chrysler_data, aes(x = Enj_mean, y = Futu_Pur_mean, color = Insur_Type)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
labs(title = "Correlation between Enjoyment and Future Purchase by Insurance Type",
x = "Mean Enjoyment",
y = "Mean Future Purchase") +
theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'
ggplot(chrysler_data, aes(x = Enj_mean, y = WOM_mean, color = Insur_Type)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
labs(title = "Correlation between Enjoyment and Word of Mouth by Insurance Type",
x = "Mean Enjoyment",
y = "Mean Word of Mouth") +
theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'
ggplot(chrysler_data, aes(x = Futu_Pur_mean, y = Valu_Percp_mean, color = Insur_Type)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
labs(title = "Correlation between Future Purchase and Value Perception by Insurance Type",
x = "Mean Future Purchase",
y = "Mean Value Perception") +
theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'