df_state_year <- read_csv('/Users/mac/Downloads/mall_state_year.csv')
## Rows: 2764 Columns: 3
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): State
## dbl (2): Year, Mall_Counts
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(df_state_year)
## # A tibble: 6 × 3
## State Year Mall_Counts
## <chr> <dbl> <dbl>
## 1 Alabama 1960 1
## 2 Alabama 1961 2
## 3 Alabama 1962 2
## 4 Alabama 1963 2
## 5 Alabama 1964 2
## 6 Alabama 1965 2
static_plot <- ggplot(df_state_year, aes(x = Year, y = Mall_Counts, color = State, group = State)) +
geom_line() +
labs(
title = "Number of Malls by State Over Time",
x = "Year",
y = "Number of Malls",
color = "State"
) +
theme_minimal() +
theme(
plot.title = element_text(size = 14),
axis.title.x = element_text(size = 12),
axis.title.y = element_text(size = 12)
)
static_plot
interactive_plot <- ggplotly(static_plot) %>%
layout(showlegend = FALSE)
interactive_plot
national_trend <- df_state_year %>%
filter(!State %in% c("New York", "California")) %>%
group_by(Year) %>%
summarise(total_malls = sum(Mall_Counts, na.rm = TRUE))
national_plot <- ggplot(national_trend, aes(x = Year, y = total_malls)) +
geom_line(color = "blue", size = 1) +
labs(
title = "National Trend: Total Number of Malls Over Time",
x = "Year",
y = "Total Number of Malls"
) +
theme_minimal() +
theme(
plot.title = element_text(size = 14),
axis.title = element_text(size = 12)
)
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
national_plot
# Trend for NY and CA
ny_ca_trend <- df_state_year %>%
filter(State %in% c("New York", "California"))
ny_ca_plot <- ggplot(ny_ca_trend, aes(x = Year, y = Mall_Counts, color = State)) +
geom_line(size = 1) +
labs(
title = "Number of Malls Over Time for NY and CA",
x = "Year",
y = "Number of Malls",
color = "State"
) +
theme_minimal() +
theme(
plot.title = element_text(size = 14),
axis.title = element_text(size = 12)
)
ny_ca_plot