1

I am trying to create three boxplot graphs, each with 5 categories showing the count of three species in one hour intervals 1-5. i.e. boxplot1 showing species1 count in hours 1-5, boxplot2 showing species2 count in 1-5, and boxplot3 showing species3 count in 1-5 all in the same window.

The data is read from a .csv with five columns: Date, Hour, species1, species2, species3. 'Hour' values are numerical values 1-5 and numeric counts for each species are in corresponding columns. 'Date' denotes the date of the observation. When I plot the three boxplots side-by-side using par(mfrow) I am only given Hour categories 1 and 2 in the x-margin. I would like to have 5 categories for each species representing hours 1-5.

Here is my code:

spec1_plot=boxplot(data$spec1,data$Hour)
par(mfrow=c(1,3))
spec2_plot=boxplot(data$spec2,data$Hour)
spec3_plot=boxplot(data$spec3,data$Hour)

Here is the plot I am given: species count by hour

How can I get it to also show hours 3-5 for each species?

zx8754
  • 52,746
  • 12
  • 114
  • 209
Gir
  • 13
  • 2
  • Could you please share some reproducible data using `dput`? – Quinten Mar 22 '23 at 15:40
  • 3
    Welcome to SO, Gir! Questions on SO (especially in R) do much better if they are reproducible and self-contained. By that I mean including attempted code (please be explicit about non-base packages), sample representative data (perhaps via `dput(head(x))` or building data programmatically (e.g., `data.frame(...)`), possibly stochastically), perhaps actual output (with verbatim errors/warnings) versus intended output. Refs: https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info. – r2evans Mar 22 '23 at 15:41

1 Answers1

0

Convert the "Hour" column to factors with desired levels, see this example:

x <- mtcars
boxplot(mpg ~ cyl, data = x) 

enter image description here

#convert to factor with levels
x$cyl <- factor(x$cyl, levels = 4:10)
boxplot(mpg ~ cyl, data = x) 

enter image description here

zx8754
  • 52,746
  • 12
  • 114
  • 209