Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bump plot using value rather than rank #24

Open
hueyrb opened this issue Dec 24, 2022 · 0 comments
Open

bump plot using value rather than rank #24

hueyrb opened this issue Dec 24, 2022 · 0 comments

Comments

@hueyrb
Copy link

hueyrb commented Dec 24, 2022

Hi David

I'm working on mountaineering data with country, year, and Nclimbers. Because Nclimbers varies hugely by year and by country, I want to use Nclimbers rather than ranks.
I used your example, and it works well!
ggplot(df, aes(year, value, color = country)) +
geom_bump()

but with my data set I get errors
"1: In compute_group(...) : 'StatBump' needs at least two observations per group."
The problem seems to be that 5 countries (Argentina, Canada, France Russia, Switzerland) had no climbers two of the three years, and they are omitted from the plot. But I have a solution (below)

Here are the data:
country <- c( "Argentina", "Canada", "China", "China", "France" , "India", "India", "India", "Italy",
"Italy", "Japan", "Japan", "Japan" , "Nepal", "Nepal" , "Russia", "S Korea", "S Korea", "Spain", "Spain", "Switzerland", "UK" , "UK" , "UK", "USA", "USA" , "USA")

year <- c(1, 3, 1, 3, 2, 1, 2, 3, 1,2, 1, 2, 3, 2, 3, 3, 2, 3, 1, 2, 1, 1, 2, 3, 1, 2, 3)

Nclimbers <- c(20, 305, 35, 805, 318, 55, 206, 993, 67, 164, 156, 444, 431, 177, 377, 319, 350,
374, 16, 350, 33, 40, 429, 1007, 27, 859, 1668)

rank <- c(8, 9, 5, 4, 6, 3, 7, 3, 2, 9, 1, 2, 5, 8, 6, 8, 4, 7, 9, 5 , 6, 4, 3, 2, 7, 1, 1)

climbers <- tibble(country, year, Nclimbers, rank)

A solution is to fill in the missing years with Nclimbers = 0
climberfill <- climbers %>% tidyr::complete(country, year, fill = list(Nclimbers = 0))

Now when I run ggplot, it works, and all countries are represented!

ggplot(climberfill, aes(year, Nclimbers, color = country)) + geom_bump()

Perhaps add an explanation to the guidelines about this warning and how to deal with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant