Tsibble ploting (autoplot and ggplot)

Hi all,

I have a problem wrapping my head around how to use the autoplot function with Dates correctly. I downloaded a csv. file from here: nasdaq >https://www.nasdaq.com/market-activity/futures/us/historicall (30 year treasury bills historical data)
and tried to visualize its closing price over time. Any tips or pointers are appreciated. The ggplot visualization also looks not correct. Can I somehow make better graphs/plots?

library(dplyr)
library(lubridate) 
library(ggplot2)
library(feasts)
library(fabletools)
library(tidyverse)
library(forecast)

csv_data_3 <- read.csv("HistoricalData_5_years_US_treasury.csv")
csv_data_4 <- read.csv("nasdaq_COMP.csv")

z_treasuries5Years <- mutate(csv_data_3, Volume=NULL, Open = NULL, High = NULL, Low=NULL) %>%
  mutate(dateFormatted =  as.Date(Date,"%m/%d/%y")) 

 TsibTreasuries <- as_tsibble(z_treasuries5Years, key = Close.Last,index= dateFormatted) 
 autoplot(TsibTreasuries, Close.Last)  
 
 ggplot() +
    geom_line(TsibTreasuries, mapping = aes(x = dateFormatted,y = Close.Last)) +
    theme_minimal()+
    scale_x_continuous("Date") +
    scale_y_continuous("Closing Price") 

  #class(z_treasuries5Years$Date) for checking if date is data
library(feasts)
library(dplyr)
library(ggplot2)

z_us_treasury <- readr::read_csv("~/Downloads/HistoricalData_5years.csv") %>%
  mutate(Date = lubridate::mdy(Date)) %>%
  as_tsibble(index = Date)
#> 
#> ── Column specification ────────────────────────────────────────────────────────
#> cols(
#>   Date = col_character(),
#>   `Close/Last` = col_double(),
#>   Volume = col_character(),
#>   Open = col_double(),
#>   High = col_double(),
#>   Low = col_double()
#> )

# Using autoplot
z_us_treasury %>%
  autoplot(`Close/Last`) +
  labs(y = "Closing price", x="Date")

# Identical plot using ggplot directly
z_us_treasury %>%
  ggplot(aes(x = Date, y = `Close/Last`)) +
  geom_line() +
  labs(y = "Closing price", x="Date")

Created on 2021-07-05 by the reprex package (v2.0.0)

Comments:

1 Like

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.