The state_estate_inheritance_taxes.csv file has information on the 17 US states that either have an estate tax or an inheritance tax. The columns are:
State
: The name of the stateestate_tax
: if the state has an estate tax
(yes/no)estate_tax_exemption
: How large the value of the estate
can be before it is taxedinheritance_tax
: If the state has an inhertiance tax
(yes/no)inheritance_tax_exemption
: The amount someone can
inherit before it is taxed.If a state is not listed, like New Hampshire, then it doesn’t have an estate or inheritance tax.
taxes
## State estate_tax estate_tax_exemption inheritance_tax
## 1 Connecticut yes 13,610,000.00 $ no
## 2 Hawaii yes 5,490,000.00 $ no
## 3 Illinois yes 4,000,000.00 $ no
## 4 Iowa no yes
## 5 Kentucky no yes
## 6 Maine yes 6,800,000.00 $ no
## 7 Maryland yes 5,000,000.00 $ yes
## 8 Massachusetts yes 2,000,000.00 $ no
## 9 Minnesota yes 3,000,000.00 $ no
## 10 Nebraska no yes
## 11 New Jersey no yes
## 12 New York yes 6,940,000.00 $ no
## 13 Oregon yes 1,000,000.00 $ no
## 14 Pennsylvania no yes
## 15 Rhode Island yes 1,774,583.00 $ no
## 16 Vermont yes 5,000,000.00 $ no
## 17 Washington yes 2,193,000.00 $ no
## inheritance_tax_exemption
## 1
## 2
## 3
## 4 0 $
## 5 1,000.00 $
## 6
## 7 0 $
## 8
## 9
## 10 100,000.00 $
## 11 25,000.00 $
## 12
## 13
## 14 0$
## 15
## 16
## 17
Create the graph seen in Brightspace. Make sure to use methods seen
in the course material using ggplot()
and the other
functions needed. The graph seen in Brightspace will be a close
approximation of the graph seen here
If there are multiple conditions you want to check for (like this
example where a state can have both, only inheritance, only estate, or
neither tax), you can use case_when()
similar to how you’d
use if_else()
. See the help menu here.
Hint: If you have 4 levels in a factor but only want three to appear in a legend and control the color of the third group, you can use something like:
values = c('A' = 'blue', 'B' = 'red', 'C' = 'yellow'),
na.value = 'purple'
Then ‘D’ won’t be in the legend but the shape that represents the ‘D’ rows will be purple.
The colors used in the graph are navy, gold3, lightblue, and grey90
# Adding the tax info to the data set for the outline of each state
left_join(
x = map_data(map = "state"),
y = taxes |> mutate(region = tolower(State)),
by = "region"
) |>
mutate(
# Changing the NA values to no
estate_tax = if_else(is.na(estate_tax), 'no', estate_tax),
inheritance_tax = if_else(is.na(inheritance_tax), 'no', inheritance_tax),
# Forming the tax status of each state
tax_status = case_when(
inheritance_tax == 'no' & estate_tax == 'no' ~ 'neither',
inheritance_tax == 'yes' & estate_tax == 'no' ~ 'inheritance',
inheritance_tax == 'no' & estate_tax == 'yes' ~ 'estate',
inheritance_tax == 'yes' & estate_tax == 'yes' ~ 'both'
)
) |>
ggplot(
mapping = aes(
x = long,
y = lat,
group = group,
fill = factor(tax_status, levels = c('estate', 'inheritance',
'both', 'neither'))
)
) +
geom_polygon(
color = "white",
linewidth = 0.25
) +
labs(
title = "Does Your State Have an Estate or Inhertiance Tax?",
caption = 'State Estate & Inheritance Tax Rates and Exemptions in 2024',
fill = NULL
) +
theme_map() +
theme(
#legend.position = "bottom",
plot.title = element_text(size = 20, color = 'navy', face = 'bold'),
#plot.subtitle = element_text(hjust = 0.5, size = 14),
legend.position = 'top',
legend.justification = 'left',
legend.box.just = 'left',
text = element_text(size = 12)
) +
coord_map(
projection = "albers",
lat0 = 39, lat1 = 45
) +
scale_x_continuous(expand = c(0, 0)) +
scale_y_continuous(expand = c(0, 0)) +
scale_fill_manual(
# Picking the colors
values = c(estate = 'navy',
inheritance = 'gold3',
both = 'lightblue'),
na.value = 'grey90',
# Changing the labels in the legend
labels = c(estate = 'State Has an Estate Tax',
inheritance = 'State Has an Inheritance Tax',
both = 'State Has both an Estate Tax & Inheritance Tax')
)
The sales_tax_by_state.csv has info on the sales tax levied
by the different states. Read the data in and save it as
sales_tax
sales_tax <- read.csv('sales_tax_by_state.csv')
sales_tax
## state state_tax state_rank avg_local_tax max_local_tax
## 1 Alabama 4.00% 40 5.29% 7.50%
## 2 Alaska 0.00% 46 1.82% 7.85%
## 3 Arizona 5.60% 28 2.78% 5.30%
## 4 Arkansas 6.50% 9 2.95% 6.13%
## 5 California 7.25% 1 1.60% 4.75%
## 6 Colorado 2.90% 45 4.91% 8.30%
## 7 Connecticut 6.35% 12 0.00% 0.00%
## 8 Delaware 0.00% 46 0.00% 0.00%
## 9 Florida 6.00% 17 1.00% 2.00%
## 10 Georgia 4.00% 40 3.38% 5.00%
## 11 Hawaii 4.00% 40 0.50% 0.50%
## 12 Idaho 6.00% 17 0.03% 3.00%
## 13 Illinois 6.25% 13 2.61% 4.75%
## 14 Indiana 7.00% 2 0.00% 0.00%
## 15 Iowa 6.00% 17 0.94% 2.00%
## 16 Kansas 6.50% 9 2.15% 4.25%
## 17 Kentucky 6.00% 17 0.00% 0.00%
## 18 Louisiana 4.45% 37 5.11% 7.00%
## 19 Maine 5.50% 29 0.00% 0.00%
## 20 Maryland 6.00% 17 0.00% 0.00%
## 21 Massachusetts 6.25% 13 0.00% 0.00%
## 22 Michigan 6.00% 17 0.00% 0.00%
## 23 Minnesota 6.88% 6 1.16% 2.15%
## 24 Mississippi 7.00% 2 0.06% 1.00%
## 25 Missouri 4.23% 38 4.16% 5.88%
## 26 Montana 0.00% 46 0.00% 0.00%
## 27 Nebraska 5.50% 29 1.47% 2.00%
## 28 Nevada 6.85% 7 1.39% 1.53%
## 29 New Hampshire 0.00% 46 0.00% 0.00%
## 30 New Jersey 6.63% 8 0.02% 3.31%
## 31 New Mexico 4.88% 34 2.74% 4.06%
## 32 New York 4.00% 40 4.53% 4.88%
## 33 North Carolina 4.75% 35 2.25% 2.75%
## 34 North Dakota 5.00% 32 2.04% 3.50%
## 35 Ohio 5.75% 27 1.49% 2.25%
## 36 Oklahoma 4.50% 36 4.49% 7.00%
## 37 Oregon 0.00% 46 0.00% 0.00%
## 38 Pennsylvania 6.00% 17 0.34% 2.00%
## 39 Rhode Island 7.00% 2 0.00% 0.00%
## 40 South Carolina 6.00% 17 1.50% 3.00%
## 41 South Dakota 4.20% 39 1.91% 4.50%
## 42 Tennessee 7.00% 2 2.55% 2.75%
## 43 Texas 6.25% 13 1.95% 2.00%
## 44 Utah 6.10% 16 1.15% 4.20%
## 45 Vermont 6.00% 17 0.36% 1.00%
## 46 Virginia 5.30% 31 0.47% 2.70%
## 47 Washington 6.50% 9 2.88% 4.10%
## 48 West Virginia 6.00% 17 0.57% 1.00%
## 49 Wisconsin 5.00% 32 0.70% 2.90%
## 50 Wyoming 4.00% 40 1.44% 2.00%
The columns are:
state
: The name of the statestate_tax
: the sales tax percentage determined and
collected by the statestate_rank
: the rank of the state’s portion of the
sales taxavg_local_tax
: The average sales tax levied by
counties, towns, and cities (doesn’t count the state portion of the
sales tax)max_local_tax
: The maximum sales tax levied by a local
area (state sales tax not included)Create the graph seen in Brightspace. The graph displays the average
combined tax: state_tax
+ avg_local_tax
Hint: The csv file contains the percentage sign, which is why R reads in it as a character instead of a numeric type column. To easily extract the number from a character, look back at the dumbbell plot for house prices.
left_join(
x = map_data(map = "state"),
y = sales_tax |> mutate(region = tolower(state)),
by = "region"
) |>
# Adding a column for the average combined percentage
mutate(
combined_tax = (parse_number(state_tax) + parse_number(avg_local_tax))/100
) |>
# Creating the graph
ggplot(
mapping = aes(
x = long,
y = lat,
group = group,
fill = combined_tax
)
) +
# State outline
geom_polygon(
color = "white",
linewidth = 0.25
) +
labs(
title = "How High Are Sales Taxes in Your State?",
fill = 'Combined State & Average\nLocal Sales Tax Rates'
) +
theme_map() +
theme(
plot.title = element_text(size = 20, color = 'navy', face = 'bold', hjust = 0.5),
legend.position = 'bottom',
legend.justification = 'right',
legend.box.just = 'right',
legend.title = element_text(hjust = 0.5, size = 14, face = 'bold')
) +
coord_map(
projection = "albers",
lat0 = 39, lat1 = 45
) +
scale_x_continuous(expand = c(0, 0)) +
scale_y_continuous(expand = c(0, 0)) +
scale_fill_viridis_b(
direction = -1,
labels = scales::label_percent(accuracy = 1),
breaks = seq(0, 0.1, 0.01)
) +
guides(fill = guide_colorbar(title.position = 'top', barwidth = 14))