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_dumbbell with scales for line and dots #63

Open
fzesch opened this issue Oct 31, 2019 · 0 comments
Open

geom_dumbbell with scales for line and dots #63

fzesch opened this issue Oct 31, 2019 · 0 comments

Comments

@fzesch
Copy link

fzesch commented Oct 31, 2019

I'm trying to make a dumbbell chart with additional information about change (green/red) and significance of the change (vol) and add an additional legend for the dots at the end of the dumbbells.

Example plot:

library(ggalt)

# build data set
set.seed(1)

df <- data.frame(country=paste("Region", LETTERS[1:10]))
df$last_year <- runif(nrow(df))
df$this_year <- runif(nrow(df))
df$ydiff <- df$this_year - df$last_year
df$vol <- runif(nrow(df))


# create dumbbell plot
ggplot(df, aes(y=country, group=country)) + 
  geom_dumbbell(aes(x=last_year, xend=this_year, colour = ydiff, size=vol),
                colour_x = "blue",
                colour_xend = "yellow") +
  scale_color_gradient2(low="green", high="red") 

Now, I'd like to add a legend about what the yellow and blue dots are, but I cannot add two color scales, since I already use the gradient2 scale for the bar between the dots. Ideally, I would have a manual fill scale as an additional option to customize the plot (but then I might need long and wide data at the same time). Can you help me?

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