[R] ggplot adjust two y-axis

Charles-Édouard Giguère ce@g|guere @end|ng |rom gm@||@com
Fri Nov 24 15:14:27 CET 2023


You could also use more simply facet_wrap(~ Studien_Flaeche). 
Charles-Édouard

-----Message d'origine-----
De : Charles-Édouard Giguère <ce.giguere using gmail.com> 
Envoyé : 24 novembre 2023 09:11
À : sibylle.stoeckli using gmx.ch; r-help using r-project.org
Objet : RE: [R] ggplot adjust two y-axis

Hi Sibylle,
For that kind of data with two different scales, I generally use two graphs
that I name gg1 and gg2 and join them using gridExtra::grid.arrange(gg1,
gg2). This way, the red part of your graph is easier to interpret. 
Have a nice day,
Charles-Édouard 

-----Message d'origine-----
De : R-help <r-help-bounces using r-project.org> De la part de
sibylle.stoeckli using gmx.ch Envoyé : 24 novembre 2023 05:52 À :
r-help using r-project.org Objet : [R] ggplot adjust two y-axis

Dear R-users

Is it possible to adjust two y-axis in a ggplot differently?
- First y axis (0-60)
- Second y axis (0-2500)


### Figure 1
ggplot(Fig1,aes(BFF,Wert,fill=Studien_Flaeche))+
  geom_bar(stat="identity",position='dodge')+
  scale_y_continuous(name="First Axis", sec.axis=sec_axis(trans=~.*50,
name="Second Axis"))+
  scale_fill_brewer(palette="Set1")

Thanks a lot
Sibylle



More information about the R-help mailing list