This short document will provide an example of how to make a scatterplot with character strings plotted, rather than points. The plot will show the relationship between real GDP growth and real Investment growth. Character strings specifying the year (ie “99”, “04”) will be displayed.

setwd(path)

require(ggplot2)
## Loading required package: ggplot2
data <- read.csv("investment_gdp.csv")
data <- subset(data, Year>=1965)


# Create vector for year labels, removing the digits specifying the century.
label <- ifelse(data$Year < 2000, data$Year - 1900, data$Year - 2000)

# Add a leading "0" for the years between '99 and '10. This changes the entries in the label vector to character strings.
label[label<10] <- paste0(0,label[label<10])

# Make the plot
figure1 <- ggplot(data, aes(x=d.INV, y=GDP, label=label)) +
    geom_text(color="darkorange2") +
    ggtitle("Real GDP and Investment Growth Rates,\n1965-2014") +
    theme_bw() +
    scale_y_continuous("Real GDP growth rate") +
    scale_x_continuous("Real investment growth rate")
    
figure1

# ggsave("investment_gdp.png", figure1)