As an Economics major with a passion for finance, I chose the exploration of spending habits for my project. Economics is a science that studies human behavior in terms of scarcity. This definition emphasizes the importance of understanding how people make choices under conditions of scarcity, which directly influences their spending habits. By examining how individuals and groups allocate limited resources, I aim to uncover the underlying priorities, lifestyle choices, and their economic impacts. This project provides a platform to analyze consumer behavior comprehensively, track emerging trends, and identify ways to enhance financial planning and budgeting strategies. Moreover, by comparing spending habits domestically, I want to better my own financial behaviors in a broader context, allowing me to better understand my position in the consumers shoes.
Figure 1:
This first plot aims to look at the background information that will provide more context later on in the visuals. This scatter plot shows the average purchase frequency (calculated by dividing all purchases over a week into a rate) and average income grouped by age. From this visualization, we can notice that most people’s salaries lie between 50k to just under 65k US dollars. Additionally from this plot, we can see that the average purchase frequency over a week varies a lot between different income levels and age groups. The plot effectively demonstrates several principles of good plot making. First, it employs a scatter plot, which is an excellent choice for showing the relationship between two quantitative variables: average income and average purchase frequency. This type of plot allows viewers to easily discern patterns or correlations between the two variables. The use of color to represent average income adds an additional layer of information without cluttering the plot. The color scale used here, ‘Viridis’, is known for its clear differentiation between values, making it easy to interpret differences in income levels and helps with accessibility and color blindness. Additionally, there’s no need to add a legend here because there’s no specific color that translates to the average income. It starts off with dark colors and gets lighter as the average income (x-axis) increases. Moreover, the size of the markers is set uniformly, ensuring that the focus remains on the color coding for income rather than the size. Interactive elements, such as tooltips that appear upon hovering over a marker, provide an enhanced user experience. These tooltips contain detailed information (age, average income, and purchase frequency), which adds depth to the data visualization without overloading the viewer with information upfront. The layout and design of the plot are also well-considered. The title is clear and descriptive, centrally aligned for balance. The axis titles are appropriately labeled, providing context for what each axis represents. The additional margin at the bottom ensures that labels and titles are not cramped. Finally, the inclusion of an annotation (Fig 1.) at the bottom of the plot serves as a useful reference and explanatory tool, summarizing what the plot represents. This is particularly helpful for viewers who might come across the plot in a report or presentation without accompanying verbal or written explanation.
Figure 2:
Figure 3:
library(plotly)
library(dplyr)
library(scales) # Ensure this package is installed for rescale function
# Assuming 'customer_data' is already loaded and structured properly
# Prepare data by summarizing and sorting
average_spending_by_country <- customer_data %>%
group_by(country) %>%
summarise(Avg_Spending = mean(spending)) %>%
arrange(desc(Avg_Spending)) %>%
slice(1:10) # Top 10 countries
# Rescale the spending values for color mapping
color_values <- rescale(average_spending_by_country$Avg_Spending, to = c(0, 1))
# Create the plot
plot <- plot_ly(
data = average_spending_by_country,
x = ~Avg_Spending,
y = ~reorder(country, Avg_Spending),
type = 'bar',
marker = list(color = color_values, colorscale = 'Viridis'),
orientation = 'h'
) %>%
layout(
title = 'Top 10 Countries with Highest Average Annual Spending',
xaxis = list(title = 'Average Spending (USD)'),
yaxis = list(title = 'Country'),
showlegend = FALSE, # Hide automatic legend
annotations = list(
list(
x = max(average_spending_by_country$Avg_Spending) * 1.05,
y = 0.5,
text = 'Higher Spending →',
showarrow = FALSE,
xref = 'x',
yref = 'paper'
),
list(
x = max(average_spending_by_country$Avg_Spending) * 1.05,
y = 0.45,
text = 'Lower Spending ←/',
showarrow = FALSE,
xref = 'x',
yref = 'paper'
)
)
)
plot
Figure 4:
Figure 5:
# Load data
personal <- read.csv("/Users/zanthesoccerman/Downloads/personal expenses (no total) - Sheet1.csv")
# Convert Month to an ordered factor
personal$Month <- factor(personal$Month, levels = unique(personal$Month), ordered = TRUE)
# Melt the data to long format using tidyr's pivot_longer instead of gather (which is being retired)
personal_long <- personal %>%
pivot_longer(cols = -Month, names_to = "Category", values_to = "Amount")
# Create a ggplot
p <- ggplot(personal_long, aes(x = Month, y = Amount, group = Category, color = Category)) +
geom_line() +
scale_y_continuous(labels = scales::comma) +
labs(title = "Personal Expenses Over Time",
x = "Month",
y = "Expense Amount") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) # Rotate x-axis text
# Convert ggplot to an interactive plotly object
ggplotly(p, tooltip = c("x", "y", "color"))
Figure 8: