Re: [R] ggplot adjust two y-axis

2023-11-24 Thread John Kane
https://r-graph-gallery.com/line-chart-dual-Y-axis-ggplot2.html On Fri, 24 Nov 2023 at 12:08, Charles-Édouard Giguère wrote: > Hi, > Just find a scaling factor that would make the two sets of data comparable. > Here I divided the second row by 5 and did the same for the second axis. > Charles-Éd

Re: [R] ggplot adjust two y-axis

2023-11-24 Thread Charles-Édouard Giguère
Hi, Just find a scaling factor that would make the two sets of data comparable. Here I divided the second row by 5 and did the same for the second axis. Charles-Édouard F1 <- as.table(matrix(c(50,11,6,17,16,3,1,2237,611,403,240,280,0,0), 2,7)) barplot(F1, beside = TRUE, col = c("blue", "grey")) a

Re: [R] ggplot adjust two y-axis

2023-11-24 Thread sibylle.stoeckli
Dear Charles-Edouard Thanks a lot. Yes indeed barplot sounds excellent. Unfortunately, the scale of the smaller axis is fixed, even If I am able to draw to axes. The idea is to expand the scale to the scale to the second axis for comparison. F1 <- as.table(matrix(c(50,11,6,17,16,3,1,2237,611,403,

Re: [R] ggplot adjust two y-axis

2023-11-24 Thread Charles-Édouard Giguère
Hi, I don't know the axis mecanism well enough in ggplot but using the original barplot function you can add an axis on the right using the axis function. Here is an example: test <- as.table(matrix(c(2,10,3,11), 2,2)) barplot(test, beside = TRUE, col = scales::brewer_pal(palette = 1)(2)) axis(

Re: [R] ggplot adjust two y-axis

2023-11-24 Thread Charles-Édouard Giguère
You could also use more simply facet_wrap(~ Studien_Flaeche). Charles-Édouard -Message d'origine- De : Charles-Édouard Giguère Envoyé : 24 novembre 2023 09:11 À : sibylle.stoec...@gmx.ch; r-help@r-project.org Objet : RE: [R] ggplot adjust two y-axis Hi Sibylle, For that kind of data wi

Re: [R] ggplot adjust two y-axis

2023-11-24 Thread Charles-Édouard Giguère
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] ggplot adjust two y-axis

2023-11-24 Thread sibylle.stoeckli
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=~.*