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

geom_bump links reappearing values #30

Open
Haclio opened this issue Apr 22, 2024 · 1 comment
Open

geom_bump links reappearing values #30

Haclio opened this issue Apr 22, 2024 · 1 comment

Comments

@Haclio
Copy link

Haclio commented Apr 22, 2024

Hi!

I just started using ggbump and I'm surprised by the behavior of the lines when previously shown missing values reappear, when axis limits are set.

I'm sure I'm not clear so here's an example :

test <- data.frame(Time = rep(seq(1:3), 4),
                   Type = rep(letters[1:4], each = 3),
                   rank = c(4, 2, 4, 2, 4, 3, 3, 3, 2, 1, 4, 1))

This small dataframe simulates rank data with 4 ranks, but imagine I want to show only 3. If I do that with geom_line:

ggplot(test, aes(x = Time, y = rank, color = Type)) +
    geom_line(linewidth = 4) +
    geom_point(size = 10) +
    ylim(1, 3)

plot_85
Take the purple points. There are two values that are shown and one that is out of bounds, and they're not linked.

Now if I replace geom_line with geom_bump:

ggplot(test, aes(x = Time, y = rank, color = Type)) +
    geom_bump(linewidth = 4) +
    geom_point(size = 10) +
    ylim(1, 3)

plot_84
geom_bump draws lines between unlinked points as it seems it ignores the existence of out of bounds values. I expected it to behave like geom_line in that regard.

I might have missed something, but is it the intended behavior?

@Haclio Haclio changed the title geom_bumps links returning values geom_bump links returning values Apr 22, 2024
@Haclio Haclio changed the title geom_bump links returning values geom_bump links reappearing values Apr 22, 2024
@MayBeche
Copy link

MayBeche commented Nov 28, 2024

I have the same issue. Did you found a solution?
I tried changing my out-of-bounds data with NA but it changes nothing...

edit : I finally found the solution !

When writing this part:
p <- Resultat %>%
ggplot(aes(order, rank, color = Risques, group = Risques)) +
geom_bump(smooth = 15, linewidth = 2, alpha = 0.2) +
scale_y_reverse()

p<- p+ geom_bump(data = Resultat%>% filter(rank <=10),
aes(order, rank, group = group, color = Risques),
smooth = 15, linewidth = 2, inherit.aes = F, na.rm = TRUE)+ scale_color_manual(values = color_graph )

In the geom_bump, group in aes must be set on the variable called "group" and not the variable I call Risques.
When the value for one categorie is out-of-bound and then back in the top X, the group variable will change. This way, in the geom_bump, they are considered to be 2 different groups and therefore will not be linked.

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

2 participants