Learn R Programming

SciencesPo (version 1.3.9)

plotTitleSubtitle: Add Title and Subtitle to a ggplot Object

Description

A production function to make it easy to add title and subtitle to ggplot2 objects.

Usage

plotTitleSubtitle(title, subtitle = "")

Arguments

title
A character string as title.
subtitle
A character string as subtitle.

encoding

UTF-8

Examples

Run this code
# setup data
set.seed(51)
supply <- rnorm(100,mean=15-seq(1,6,by=.05),sd=1)
demand <- rnorm(100,mean=4+seq(1,21,by=.2),sd=.5)
time<-seq(1,100,by=1)
data <- data.frame(time, supply,demand)

# make the plot
library(ggplot2)
ggplot(data,aes(time)) +
geom_line(aes(y=demand),size=1.6) +
geom_line(aes(y=supply),size=1.6) +
annotate("text",x=90,y=12,label="Demand",colour="red") +
annotate("text",x=80,y=23,label="Supply",colour="blue") +
plotTitleSubtitle("My Title", "My Subtitle")

Run the code above in your browser using DataLab