Rich Shepard
2021-Nov-11 17:22 UTC
[R] ggplot2: multiple box plots, different tibbles/dataframes
On Thu, 11 Nov 2021, Avi Gross wrote:> Boxplots like many other things in ggplot can be grouped in various ways. > I often do something like this:Avi, I've designed and used multiple boxplots in many projects. They might show geochemical concentrations at two locations or in two (or three) separate time periods. All data in a single dataframe.> To display multiple boxplots subdivided by place is as easy as using the > phrase in an aes() clause like: > > ggplot(your_data, aes(..., color=PLACE)) + geom_boxplot()What I need to plot are multiple 'your_data' sets. I'll be testing this: ggp <- ggplot(NULL, aes(x, y)) + # Draw ggplot2 plot based on two data frames geom_point(data = data1, col = "red") + geom_line(data = data2, col = "blue") ggp # Draw plot today, but using four boxplots. Regards, Rich
Avi Gross
2021-Nov-11 17:35 UTC
[R] ggplot2: multiple box plots, different tibbles/dataframes
Rich, I think we have suggested something several times that you ignore as you are focused on your way of thinking. If you read the last part of the letter I wrote in public, I suggest combining your multiple dataframes into one if they are compatible and including a new column called something like PLACE. The existence of that variable lets you tell ggplot you want MULTIPLE plots placed in a grid based on that variable OR in other words, asking ggplot to subdivide your data into four parts and make one plot for each and then place them into a matrix. I will not spell out the many variations you can make but some variations have you add another layer to the ggplot that may use formula notation to specify what combination of variables to do the subdivisions by or specifying you want then in rows (meaning vertically stacked) based on a variable and so on. Look up facet_grid() and facet_wrap() as various ways to do this. Note you may want to examine some options such as setting the scales to be the same or free. -----Original Message----- From: R-help <r-help-bounces at r-project.org> On Behalf Of Rich Shepard Sent: Thursday, November 11, 2021 12:22 PM To: r-help at r-project.org Subject: Re: [R] ggplot2: multiple box plots, different tibbles/dataframes On Thu, 11 Nov 2021, Avi Gross wrote:> Boxplots like many other things in ggplot can be grouped in various ways. > I often do something like this:Avi, I've designed and used multiple boxplots in many projects. They might show geochemical concentrations at two locations or in two (or three) separate time periods. All data in a single dataframe.> To display multiple boxplots subdivided by place is as easy as using > the phrase in an aes() clause like: > > ggplot(your_data, aes(..., color=PLACE)) + geom_boxplot()What I need to plot are multiple 'your_data' sets. I'll be testing this: ggp <- ggplot(NULL, aes(x, y)) + # Draw ggplot2 plot based on two data frames geom_point(data = data1, col = "red") + geom_line(data = data2, col = "blue") ggp # Draw plot today, but using four boxplots. Regards, Rich ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Bert Gunter
2021-Nov-11 17:52 UTC
[R] ggplot2: multiple box plots, different tibbles/dataframes
You can always create a graphics layout and then plot different ggplot objects in the separate regions of the layout. See ?grid.layout (since ggplots are grobs) and ?plot.ggplot . This also **may** be useful by showing examples using grid.arrange() https://cran.r-project.org/web/packages/egg/vignettes/Ecosystem.html Still, I suspect that Jeff Newmiller may be right about needing to structure your data more appropriately for what you wish to do. Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Thu, Nov 11, 2021 at 9:22 AM Rich Shepard <rshepard at appl-ecosys.com> wrote:> > On Thu, 11 Nov 2021, Avi Gross wrote: > > > Boxplots like many other things in ggplot can be grouped in various ways. > > I often do something like this: > > Avi, > > I've designed and used multiple boxplots in many projects. They might show > geochemical concentrations at two locations or in two (or three) separate > time periods. All data in a single dataframe. > > > To display multiple boxplots subdivided by place is as easy as using the > > phrase in an aes() clause like: > > > > ggplot(your_data, aes(..., color=PLACE)) + geom_boxplot() > > What I need to plot are multiple 'your_data' sets. I'll be testing this: > ggp <- ggplot(NULL, aes(x, y)) + # Draw ggplot2 plot based on two data frames > geom_point(data = data1, col = "red") + > geom_line(data = data2, col = "blue") > ggp # Draw plot > > today, but using four boxplots. > > Regards, > > Rich > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.