d2jsp
Log InRegister
d2jsp Forums > Off-Topic > General Chat > Homework Help > R Studio > I Just Need Some Labels!!!
Add Reply New Topic New Poll
Member
Posts: 8
Joined: Aug 27 2019
Gold: 0.00
Sep 22 2019 03:05pm
So I'm trying to get tick labels on my graph, here is my code and links to the datasets. Let me know what I'm doing wrong with the graph

Datasets:
Download the data for the unemployment rate https://fred.stlouisfed.org/series/UNRATE
Download the data for the Consumer Price Index for All Urban Consumers: All Items. https://fred.stlouisfed.org/series/CPIAUCSL

Graph code with the doodoo
Code

ts.plot(fred1, gpars = list(col = c("blue", "red"), main = "Time Series Plot of CPI and Unemployment Rate", xlab = "Months", las=2))
legend("topleft", legend = colnames(fred1), col = 1:2, lty = 1)
scale_x_datetime(date_breaks='10 Years', date_labels = '%b-%y')


Basically I want the "Month-Year" to appear instead of the Nth observation as a value on the x-axis. The last line doesn't show an error but doesn't do anything to the graph.


Entire code:
Code

library(readxl)
library(ggplot2)
library(zoo)
library(XLConnect)
library(dplyr)
library(lubridate)
setwd("C:/Users/jhoel/Documents/2019 Fall/1 Stats/Stats Data/HW3")
CPI <- read_excel("CPIAUCSL.xls", skip = 10)
View(CPI)
UNR <- read_excel("UNRATE.xls", skip = 10)
View (UNR)
CPI2 <- tail(CPI, -12)
fred <- merge(CPI2, UNR, by="observation_date", all=TRUE)
fred1 <- as.ts(fred[,2:3], start = c(1947, 1), frequency = 12)
rownames(fred1) <- format(as.yearmon(fred$observation_date), "%b %Y")
ts.plot(fred1, gpars = list(col = c("blue", "red"), main = "Time Series Plot of CPI and Unemployment Rate", xlab = "Months", las=2))
legend("topleft", legend = colnames(fred1), col = 1:2, lty = 1)
scale_x_datetime(date_breaks='10 Years', date_labels = '%b-%y')
Go Back To Homework Help Topic List
Add Reply New Topic New Poll