Ggplot title error

Hi,

Greetings from Manila.
I’m working on the following ggplot and unfortunately I can’t pinpoint my error; hope someone can help me:

pacman::p_load(   #p_load is function in the pacman package; do this once
  rio,       # for importing data (always used)
  here,      # for locating files
  skimr,     # for reviewing the data (always used)
  janitor,   # for data cleaning (always used)
  lubridate, # for date cleaning
  epikit,    # for creating age categories
  gtsummary, # for nice tables
  flextable, # for making pretty tables
  scales,   # percent
  treemap,  #treemap
  remotes,  #needed for treemap
  ggExtra,  #other functions for ggplot
  gganimate, #moving graphs
  animation,
  extrafont,
  forcats,   # convert data structure to factors (with levels); not really needed to install because it's under tidyverse
  tsibble,   #used for time series analysis, has a variety of useful time/date functions.
  tidyverse) # for data management and visualization (includes ggplot)


data <- data.frame(
  Team = c("BOQ", "APPLIEDEpi", "WHO", "RITM"),  #change col names
  Energy = c(55, 60, 30, 70)
)

data
#>         Team Energy
#> 1        BOQ     55
#> 2 APPLIEDEpi     60
#> 3        WHO     30
#> 4       RITM     70

ggplot(data, aes(x=reorder(Team,Energy), y=Energy, label = Energy)) +
  geom_point(size = 6, color = "moccasin", shape = 21) +
  geom_segment(aes(x=Team, xend=Team, y=0, yend=Energy), color="turquoise", size=3) + 
  geom_text(color = "coral", size = 3) +
  labs(ytitle = "Average Energy Level during Mobility Break",
       caption = "esp.if it involves dancing & singing") +
  theme_minimal() +
  theme(axis.title = element_blank(),
        panel.grid.minor = element_blank(),
        legend.position = "none",
        text = element_text(family = "Hydrophilia Iced"),
        axis.text.y = element_text(size = 8),
        plot.ytitle = element_text(size = 16, margin = margin(b = 10), hjust = 0),
        plot.caption = element_text(size = 8, margin = margin(t = 10), color = "grey70", hjust = 0))
#> Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
#> ℹ Please use `linewidth` instead.
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
#> generated.
#> Error in `mapply()`:
#> ! The `plot.ytitle` theme element is not defined in the element
#>   hierarchy.

Thank you.

Regards,
Echo

1 Like

Hi Echo,
Thank you for your question.
We suggest looking inside your labs and theme functions - ytitle is not a known element of ggplot. We think you mean title.
Also we think there is an measurement error - surely Applied Epi has higher energy levels?
Paula, Jason, and Hendrik :slight_smile:

3 Likes

Hello Paula,

Thank you so much.
Couldn’t agree more that Applied Epi has higher energy levels.