I have the following data set:
tax <- tribble(
~ Country, ~ `1970`, ~ `1979`,
"Sweden", 46.9, 57.4,
"Netherlands", 44.0, 55.8,
"Norway", 43.5, 52.2,
"Britain", 40.7, 39.0,
"France", 39.0, 43.4,
"Germany", 37.5, 42.9,
"Belgium", 35.2, 43.2,
"Canada", 34.9, 35.8,
"Finland", 34.9, 38.2,
"Italy", 30.4, 35.7,
"United States", 30.3, 32.5,
"Greece", 26.8, 30.6,
"Switzerland", 26.5, 33.2,
"Spain", 22.5, 27.1,
"Japan", 20.7, 26.6
)
I am trying to create a slopegraph (x axis 1970, and 1979) y axis the values from the years, and create labels for the countries. However I am running into the problem that some of the values aren’t unique so they lay on top of eachother. This isn’t the behavior that I want, I want each point to have a unique position on the axis. Im trying to recreate a plot as practice. So far the code I have: (haven’t gone much deeper on polishing the plot or adding the labels because I can’t seem to figure out how to get the points to not overlap.) I have tried jittering them but it doesn’t work as intended.
tax |>
pivot_longer(
cols=c("1970", "1979"),
names_to="Year",
values_to="Tax"
) |>
ggplot() +
geom_line(
aes(x=Year, y=Tax, group=Country)
) +
geom_point(
aes(x=Year, y=Tax, group=Country)
)