University Boxplot Assignment

Hi everyone,

I was recently given an assignment to create a box plot from a set of data that my professor gave us in class.

Everything goes fine until I finish this line of code:

# Libraries
library("tidyverse")
library("ggplot2")
library("dplyr")
library("RColorBrewer")
library("extrafont")

load(file.choose())

d <- d %>% pivot_longer(
  cols = 2:3,
  names_to = "Depth",
  values_to = "Abundance"
)

ggplot(d, aes(Trajectory, Abundance)) +
  geom_boxplot()

While I attached a screenshot of the requirements down below for you guys to read, I still need to change the default layout, colors, and fonts, that of which I'm not entirely sure what to do. We had done an assignment before where we had to change those types of things but when I tried incorporating my code from the last assignment over to this one, none if it worked.
[Screenshot of HW - Redacted by mod]

Hi, welcome!

Please have a look to our homework policy, homework inspired questions are welcome but they should not include verbatim instructions from your course.

oh ok, so should I list out by myself what I need help with?

Probably most of what you might wish to know would be here :
18 Themes | ggplot2 (ggplot2-book.org)

If you have an specific questions please feel free to ask, without quoting an homework verbatim.

1 Like

I took a look at that, however I think a big issue with that is that it doesn't take into account that I already a dataset plugged into the box plot — I'm not necessarily starting from scratch in my case

For sure its taken into account, because its entirely concerned with applying themes and styling to plots , that have datasets behind them....
lets go step by step.
Here is some boxplot:

(p <- ggplot(mpg, aes(class, hwy)) + geom_boxplot())

if you follow 18 Themes | ggplot2 (ggplot2-book.org)
you will see how for example, if you wanted the axis text to be red and size 12 you can do :

  p+theme(axis.text = 
            element_text(colour = "red",size=12))

its an issue of being clear on what modification you want to make, and using a tutorial / reference of the kind I shared in order to see how to do it.

Here is another excellent reference I found, this might be particularly good for you as it visually labels what the controllable components are called.
ggplot2 Theme Elements Demonstration | Henry Wang

You can add theme() material by putting in + theme() (with the desired arguments) in the same line where you put geom_boxplot().

Alternatively, save the results of ggplot() in a new variable and then go newVariable + theme().

Either way, you are just adding to what you've already done.

This topic was automatically closed 21 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.