[R] ggplot2: multiple box plots, different tibbles/dataframes

Rich Shepard r@hep@rd @end|ng |rom @pp|-eco@y@@com
Thu Nov 11 19:24:34 CET 2021


On Thu, 11 Nov 2021, Avi Gross via R-help wrote:

> Say I have a data.frame with columns called PLACE and MEASURE others. The
> one I call PLACE would be a factor containing the locations you are
> measuring at. I mean it would be character strings of your N places but
> the factors would be made in the order you want the results in. The
> MEASURE variable in each row would contain one of the many measures at
> that location. You probably would have other columns like DATE.

Avi/Jeff/Burt,

Here are the head and tail of one data file:
site_nbr,year,mon,day,hr,min,tz,cfs
14174000,1986,10,01,00,30,PDT,11900
14174000,1986,10,01,01,00,PDT,11900
14174000,1986,10,01,01,30,PDT,11900
14174000,1986,10,01,02,00,PDT,11800
14174000,1986,10,01,02,30,PDT,11800
14174000,1986,10,01,03,00,PDT,11800
14174000,1986,10,01,03,30,PDT,11800
14174000,1986,10,01,04,00,PDT,11800
14174000,1986,10,01,04,30,PDT,11800
...
14174000,2021,09,30,23,12,PDT,5070
14174000,2021,09,30,23,17,PDT,5070
14174000,2021,09,30,23,22,PDT,5050
14174000,2021,09,30,23,27,PDT,5050
14174000,2021,09,30,23,32,PDT,5050
14174000,2021,09,30,23,37,PDT,5050
14174000,2021,09,30,23,42,PDT,5050
14174000,2021,09,30,23,47,PDT,5050
14174000,2021,09,30,23,52,PDT,5050
14174000,2021,09,30,23,57,PDT,5050

(Water years begin October 1st and end September 30th.)

The other three locations have the same format.

The boxplots for each PLACE (site_nbr) should summarize all MEASURE (cfs)
values for all recorded data (DATE).

The R tibbles have a datetime column which could be the DATE.

If I assemble all 4 sites into a single tupple I suppose it would have three
columns PLACE (the grouping factor), DATE (on the x axis), and MEASURE (cfs on
the y axis) and each boxplot would be grouped so the
command would be:

disc_plot <- ggplot(df, aes(x = group, y = cfs)) +
 	geom_boxplot()

Is this close?

Thanks,

Rich



More information about the R-help mailing list