How do I make a plot showing the amount owed every month.

Hello! I firstly needed to compute how many months will it take me to repay my loan. And after the getting value of 158 months I need help producing a plot that will show amount owed each month.

My loan is 1,000 euro. Annual interest rate of 11%, compounded
monthly. And the monthly repayments are 12 euro

loan <- 1000
monthlyrate <- 0.11/12
repayment <- 12
month <- 0
target <- 0

while(loan > target){
month <- month + 1
interestpayment <- round(loan*monthlyrate,2)
loan <- loan - (repayment - interestpayment)
}
month - 1

Hi @sonjiiic,
Welcome to the RStudio Community Forum.

You need to set-up a vector to contain the balance at each month, and then save to that vector for each step inside the while loop. Then you can use the vector to plot the loan progress:

loan <- 1000
monthlyrate <- 0.11/12
repayment <- 12
month <- 0
target <- 0
balance <- vector()

while(loan > target){
month <- month + 1
interestpayment <- round(loan*monthlyrate,2)
loan <- loan - (repayment - interestpayment)
#print(loan)
balance[month] <- loan
}

plot(x=1:length(balance), y=balance, type="l", 
     xlab="Time in months",
     ylab="Remaining balance ($)")

Created on 2021-11-27 by the reprex package (v2.0.1)

This topic was automatically closed 21 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.