Graph Titles in Tidyverse

I'm new to R and trying to figure how how to add titles to graphs i've tried adding

Title(main = "Spotify Plays,
sub ="2023")

Please see my full code below.

library(tidyverse)

View(Spotify_Stats_Oct_23)

Spotify_Stats_Oct_23 %>%

ggplot(aes(Date, Plays))+
geom_point(size = 2, alpha = 0.3)+
geom_line(size = 1)
theme_minimal()

View(SpotifyCountries)

Title(main = "Spotify Plays,
sub ="2023")

SpotifyCountries %>%
ggplot(aes(Date, Plays, colour = Location))+
geom_point(size = 2, alpha = 0.3)+
geom_line(size = 1)+
theme_minimal()

Language of graphs:

ggplot(data) + geom_[](aes()) + labs()

the labs function lets you add:

title, subtitle, caption, etc.

see more at labs on tidyverse

Thanks but when i add like so it doesn't seem to work

library(tidyverse)

View(Spotify_Stats_Oct_23)

Spotify_Stats_Oct_23 %>%

ggplot(aes(Date, Plays))+
geom_point(size = 2, alpha = 0.3)+
geom_line(size = 1)
theme_minimal()

View(SpotifyCountries)

SpotifyCountries %>%
ggplot(aes(Date, Plays, colour = Location))+
geom_point(size = 2, alpha = 0.3)+
geom_line(size = 1)+
theme_minimal()

labs(
title = "Spotify Plays"(),
subtitle = "2023"(),
)

@JamieC77 remember that ggplot work by layers, must be joined by +. So, you need some this symbols.

SpotifyCountries %>%
  ggplot(aes(Date, Plays, colour = Location))+
  geom_point(size = 2, alpha = 0.3)+
  geom_line(size = 1)+
  theme_minimal() +
  labs(title = "Spotify Plays",
      subtitle = "2023")

Thank you for your help yeah, figured that out by playing around with the code shortly after posting on here.

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.