Reputation: 485
I have the following plot like below. It was created with this command:
popanim <- ggplot(data = pop2, aes(
x = age1,
y = ifelse(gender == 1, -pop_rel, pop_rel),
fill = gender,
group = district
)) +
geom_col() +
# facet_wrap( ~ country) +
coord_flip() +
transition_states(district, transition_length = 2, state_length = 1) +
labs(title = 'district: {closest_state}')+
xlab("age") + ylab("population") #HERE
anim_pop <- animate(popanim, nframes = 50, renderer = gifski_renderer("gganimate.gif"))
anim_save(anim_pop = anim_pop, filename ="//pyramidd.gif")
Now next thing I want to do is to modify the legend value from 1 into male
and 2 into female
I have tried scale_fill_discret
but it does not work
Upvotes: 0
Views: 229
Reputation: 3294
You can do scale_fill_discrete(labels = c("Male", "Female"))
. Here I show a reproducible example since you have not provided reproducible data (which is always recommended):
library(ggplot2)
ggplot(mtcars, aes(hp, mpg, fill = factor(cyl))) +
geom_col() +
coord_flip() +
scale_fill_discrete(labels = c("Male", "Female", "Other"))
Upvotes: 1