Plot side-by-side box plots of the data (in one plot). Label the plot appropriately.

I have an excel file that I've attached and read, and the x variable is non-numerical. this is the code line I tried to use to make a side by side box plot

     boxplot(fishjump$Treatment~fishjump$Time, xlab="Treatment",ylab="Time",names=c("Control","Air")

but it won't run can someone help, please :slight_smile:

Use the ggplot2 package. The syntax for a boxplot is pretty straightforward from there.

ggplot(data=fishjump,aes(x=Treatment,y=Time)) + 
geom_boxplot()

i don't think my prof allows that tbh so I kinda have to do it with just r

ggplot2 is just a package in R. It is part of the tidyverse, which is the most widely used data analytics package in R. You can use it in your version of R by running either of the following blocks of code in the consol.

install.packages("tidyverse")
library(tidyverse)
install.packages("ggplot2")
library(ggplot2)

Try

 boxplot(fishjump$Time ~ fishjump$Treatment, xlab="Treatment",ylab="Time",names=c("Control","Air")

I think the categorical variable needs to follow the numeric.

A slightly tidier way to write this would be:

 boxplot(Time ~ Treatment, data = fishjump, xlab="Treatment",ylab="Time",names=c("Control","Air")

It makes it a bit easier to see what you are doing. In any case I like @ BLukomski' suggestion to use ggplot2

thank youuuu it worked

i have another question when i add a title would i have to add it to my original line or is there a way to do it in a new line? I'm not familiar with ggplot at all, I barely understood normal r studio

You should be able to do this:

ggplot(data=fishjump,aes(x=Treatment,y=Time)) + 
geom_boxplot() +  ggtitle("Hela Plot")

i have another question, i feel bad for asking so many but I've tried like 40 lines and non worked so I really need the help

I need to make a Q-Q plot for the 2 variables under "treatments" separately, but I can't figure out how to tell the program that the variable "air" and "Control" are different. but while still in a line that makes the graph I need. I'm not sure if that makes sense but under "treatment" its not numeric values, but instead "Air" and "control"

In this case, you can use qqnorm() and the subset function to make two QQ plots of the Time data, subsetted based on the two groups.

qqnorm(subset(fishjump,Treatment=="Control")$Time)
qqnorm(subset(fishjump,Treatment=="air")$Time)

this still doesn't separate my x values, id got something similar yesterday night but the issue is I still have all my x vales included on the graph

My mistake. Use two equals signs

Try

qqnorm(subset(fishjump,Treatment == "Control")$Time)

Or to break it down to component commands

fcontrol <-   subset(fishjump, Treatment == "Control")
qqnorm(fcontrol)

just curious if my x and y were both numerical values is it possible to make a qqnorm plot with both in 1?

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.