1

I am trying to make part of my title in italics (M.alfredi) but cant figure out how? Can anyone help? Thanks.

library(tidyverse) 
library(reshape2)
dat <- read_xlsx("ReefPA.xlsx")
names(dat) <- str_replace_all(names(dat), " ", "_") 
dat1 <- dat d
at1$Date <- format(dat1$Date, "%Y/%m")

dat1 %>% 
  group_by(Date) %>% 
  tally() %>% 
  filter(Date > '2014-01-01') %>% 
  ggplot() + 
  geom_bar(aes(x = Date, y = n), stat = 'identity') + 
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1)) + 
  ylab("Total Number of M.alfredi Encounters Per Month")

enter image description here

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87

1 Answers1

1

You can use plotmath expressions to label your axis. There is no sample data here, but this mock-up should suffice:

ggplot(data = data.frame(x = 1:30, y = round(runif(30, 20, 50))), aes(x, y)) + 
  geom_col() +
  labs(y = expression("Total Number of "~italic(M.alfredi)~"Encounters Per Month"))

enter image description here

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87
  • As the title is quite long I am trying to separate it over two lines with '\n'. However, using the italics seems to mess with the formatting of this - do you know a way around this? – Aimee Nicholson-Jack Aug 16 '20 at 16:14