I´m trying to create a bar chart, but I´m getting an error like:
Scale for 'fill' is already present. Adding another scale for 'fill', which will replace the existing scale.
I identified the problem as trying to use two scale_fill functions. If I remove one of them (scale_fill_brewer or scale_fill_discrete), it works.
ggplot(df_postgres, aes(x=as.factor(language), y=total/1000, fill=type)) +
geom_bar(stat='identity', color = 'black')+
geom_text(mapping=aes(label=ifelse(type=='A', (paste(as.character(floor(total/1000)),'K') ), '')), vjust=-0.7,color='black')+
scale_x_discrete(name="Language")+
scale_y_continuous(name="Repos (thousands)")+
scale_fill_brewer(palette='Pastel1')+
scale_fill_discrete(name="Proportion",labels=c("Language","Others"))
My question is: how can I set the discrete options AND the nice palette option? I´m a newbie in R, but can´t find a response to this specific error.
The ...
argument to scale_fill_brewer
will take arguments that will be passed to scale_fill_discrete
.
So move your name
and labels
arguments to scale_fill_brewer
, delete your scale_fill_discrete
and everything should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With