'Why is my dumbell plot not increasing with xend?

This is my dataframe:

mydf <- structure(list(NOME = c(1, 1, 6, 6, 5, 5, 3, 3, 9, 9), PLAYER.POSITION = c(
  "LATERAL",
  "LATERAL", "EXTREMO", "EXTREMO", "MEIOCAMPO", "MEIOCAMPO", "CENTRAL",
  "CENTRAL", "AVANCADO", "AVANCADO"
), Time = c(
  "PRIMEIRA PARTE",
  "SEGUNDA PARTE", "PRIMEIRA PARTE", "SEGUNDA PARTE", "PRIMEIRA PARTE",
  "SEGUNDA PARTE", "PRIMEIRA PARTE", "SEGUNDA PARTE", "PRIMEIRA PARTE",
  "SEGUNDA PARTE"
), values = c(
  104L, 81L, 108L, 100L, 101L, 100L,
  95L, 90L, 96L, 51L
)), row.names = c(NA, -10L), class = c(
  "tbl_df",
  "tbl", "data.frame"
))

library(ggalt)

df_final <- mydf %>% pivot_wider(names_from = Time, values_from = values)

ggplot(
  data = df_final,
  aes(
    x = 1, xend = 2,
    y = `PRIMEIRA PARTE`, yend = `SEGUNDA PARTE`,
    label = NOME
  )
) +
  geom_dumbbell(
    colour_x = "#5b8124", colour_xend = "#bad744",
    size_xend = 5, size_x = 12,
    dot_guide = TRUE, dot_guide_size = 0.25
  )

Why the lines are paralell? This should follow the increase/decrease between PRIMEIRA PARTE and SEGUNDA PARTE columns right?

I think I did something wrong with groupargument.



Solution 1:[1]

Your description is unclear, but this might be closer to what you had in mind:

ggplot(data = df_final ,
       aes(y = PLAYER.POSITION, yend = PLAYER.POSITION,
           x = `PRIMEIRA PARTE`, xend = `SEGUNDA PARTE`,
           label =  NOME)) +
  geom_dumbbell(colour_x = "#5b8124", colour_xend = "#bad744",
                size_xend = 5,size_x = 12,
                dot_guide=TRUE, dot_guide_size=0.25) + 
  geom_text(colour = 'white') +
  labs(x = NULL)

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1