@paul this is the Data I have used Date
Date Notional
30/06/1998 72106521.77
31/12/1998 80276622.05
30/06/1999 81420274.61
31/12/1999 88156431.71
30/06/2000 93959822.42
31/12/2000 95150854.68
30/06/2001 99648589.78
31/12/2001 111058769.9
30/06/2002 127372621.6
31/12/2002 141513417.2
I calculated percent using Notional_change <-(((Notional_amount[2:n, 1]-Notional_amount[1:(n-1),1])/Notional_amount[1:(n-1),1])*100)
My code are here
library("ggplot2")
library("scales")
library(tidyverse)
OTCData <- read.csv("~/r programs/Research/DerivativeMeasure.csv")
OTCData <- mutate(OTCData, Date = as.Date(OTCData$Date, "%m/%d/%Y"))
Notional_amount <-OTCData[,"Notional", drop=FALSE]
#rownames(Notional_amount) <- OTCData$Date
n <-nrow(Notional_amount)
Notional_change <-(((Notional_amount[2:n, 1]-Notional_amount[1:(n-1),1])/Notional_amount[1:(n-1),1])*100)
class(Notional_change)
names(Notional_change) <- OTCData[2:n, 1]
head(Notional_change)
# get the rescaling factor from the max of the numerical column and the max percent
n_max <- max(OTCData$Notional, na.rm = TRUE)
p_max <- max(Notional_change, na.rm = TRUE)
scaling_factor <- p_max / n_max
ggplot(OTCData, aes(x = OTCData$Date)) +
geom_line(aes(y = Notional, color="red"), group =1) +
geom_line(aes(y = Notional_change / scaling_factor, colour = "blue"), group =1) +
scale_colour_identity(name = NULL, breaks = c("red", "blue"), labels = c("Notional", "Percent"), guide = "legend") +
scale_y_continuous(
name = "Notional Axis",
sec.axis = ggplot2::sec_axis(~ . * scaling_factor,
name = "Percent Axis",
labels = scales::percent_format(accuracy = 1))
)
The error I am getting is here:
Version:1.0 StartHTML:0000000107 EndHTML:0000000984 StartFragment:0000000127 EndFragment:0000000966
Error: Aesthetics must be either length 1 or the same as the data (44): y
The problem seem to be transposing Notional_change, how can I do it? please help