Interested in making net worth progress graphs that look just like mine? Do you also want an introduction to computer programming in R? Well, what a coincidence, this post will cover both of those things! Read on to learn how to graph your net worth using R!
I think that R is one of the best languages for learning how to program, especially if you want to work with data. It’s easy to read, has a big following online who can answer questions for you, and it’s open source aka free!
Below, I broke down the process of making net worth graphs in R into a series of 10 very basic steps. All you need is a computer, and this should take less than 20 minutes.
So, get your numbers handy and get ready for a free new skill and a satisfying financial nerd-tastic graph. Go for it!
When I read this intro back to myself it sounds super gimmicky, sort of infomercial-like, but no one’s making any money off you downloading R or using my template. I’m just proselytizing R users because I think it’s a great language and I like to use it for graphing my net worth!
1. Download R
This first step is the hardest, but it’s still seriously pretty easy.
It’s free to download R. If you run Windows on your computer, click “Download R 3.3.2 for Windows” at this link: https://cran.r-project.org/bin/windows/base/
If you use a Mac, go to https://cran.r-project.org/bin/macosx/ and choose either “R-3.3.2.pkg” or “R-3.2.1-snowleopard.pkg” depending on which version of Mac OS X you’re working with.
Open the .exe file that you’ve downloaded and click “Next” or “OK” or “Finish” through all the default settings to install R.
Boom! First step done!
2. Open R
The default installation process added a shortcut to your desktop for R. Click on it to open R.
(See, this is seriously not hard!)
3. Start a new R script (that’s the fancy name for a program you write in R)
You open a new R script like you would open a new Microsoft Word document. Choose “New Script” from the File menu.
The window that pops up is called the Editor. It’s where you write R scripts.
4. Copy and paste this code
Here’s the script I use to graph my net worth. Copy it and paste it into your newly opened editor window.
Tip: If you mouse over this code snippet, a toolbar will appear at the top with a copy icon that makes it even easier to copy this code.
# PUT YOUR GOAL DOLLAR VALUES AND CORRESPONDING DATES HERE
goals = c(100000, 200000, 300000, 400000, 500000)
goaldates = c("2015-01-01", "2016-01-01", "2017-01-01",
# PUT YOUR MEASURED NET WORTH VALUES AND THE CORRESPONDING DATES HERE
values = c(100000, 200000, 300000)
dates = c("2015-01-01", "2015-07-31", "2015-08-31")
# WHAT DO YOU WANT THE TITLE OF YOUR GRAPH TO BE?
title = "Chedda Imaginary Net Worth over Time"
# WHERE DO YOU WANT THE GRAPH TO BE SAVED?
# (make sure to use forward slashes instead of backslashes)
filepath = "/blahblah/MyDocuments/goalplot.png"
# organize goal data
goaldata = data.frame(cbind(goaldates, goals))
# combine the goaldates and goals columns into a table
goaldata$rdate = as.Date(goaldata$goaldates)
# turn the goal dates into ones that R understands as dates
colnames(goaldata)[1:2] = c("dates", "values")
# rename the columns for graphing
goaldata$values = as.numeric(as.character(goaldata$values))
# make R understand the goal values as numbers
# organize value data
valuedata = data.frame(cbind(dates, values))
# combine the dates and values columns into a table
valuedata$rdate = as.Date(valuedata$dates)
# convert the dates into R date format
valuedata$values = as.numeric(as.character(valuedata$values))
# make R understand the goal values as numbers
ggplot(data=valuedata, aes(x=rdate, y=values)) +
# start graph; identify x and y axes
# plot "Actual" line
geom_line(data=goaldata, aes(color="Goal")) +
# plot "Goal" line
# add your title
labs(x="", y="Net Worth ($)") +
# add axis labels
scale_y_continuous(labels = comma) +
# add commas to y axis labels
scale_x_date(date_breaks= "1 year", date_labels="%Y") +
# format the x axis to have labels every year
# get rid of the default ugly gray background
# center the title
# get rid of default legend title
ggsave(file=filepath, width=10, height=8)
# save your plot!
5. Add in your goals
See where there’s an all-caps comment in my code that says “PUT YOUR GOAL DOLLAR VALUES AND CORRESPONDING DATES HERE”? Do that!
Your goals are net worth values that you want to reach by certain dates.
In this example code, I pretended that I wanted to get to $100k by January 1, 2015; $200k by January 1, 2016; $300k by January 1, 2017; etc.
Put your goal net worth values in between the parentheses in line 8, as plain numbers separated by commas.
Put the corresponding dates you want to reach each one by between the parentheses in lines 9 and 10, separated by commas. These dates should be formatted “yyyy-mm-dd” and each one should be within quotation marks.
6. Save your script
Just seemed like this would be a good time to remind you to save.
While you’re using the Editor window, click the Save icon on the toolbar like you would save basically any other file.
7. Add in your net worth progress
You know where it says “PUT YOUR MEASURED NET WORTH VALUES AND THE CORRESPONDING DATES HERE”? Do it.
Same as before. Lines 13-14. You want dollar values of what your net worth was at certain times, along with corresponding dates.
In the imaginary situation shown in my example code, I had $100k on January 1, 2015 and $300k on August 31, 2015.
And why not click save again for good measure. I save my script compulsively when I’m coding.
8. The title
On line 17, it says title = “…”. Between those quotation marks, fill in whatever title you want to show up at the top of your graph. If you don’t want a title, just put title = “”.
9. The filepath
You’ll want to save your lovely net worth graph to somewhere on your computer! Check out line 21 of my code.
Put the filepath of the location you want the plot saved to there between the quotation marks. It should end with whatever you want the name of your plot to be. My example is named “goalplot.png”.
Important tip: Make sure you replace any backslashes in the filepath with forward slashes. R likes them better!
10. Run it!
You don’t have to mess with any of the code below line 22. Just leave it alone, unless you already conquered the basics and you want to fiddle around.
Now highlight all of your R code and type “Ctrl-R”. Boom! You ran it!
Your shiny new plot should be saved wherever you told R to put it! Go check it out, you creator!
(Optional) Download RStudio
The images in this post have been of the RGui setup, which is the default way to use R. However, there’s a much prettier way!
If you think you’d like to use R more than just for this, you should definitely download RStudio. It’s a free (for individuals) integrated development environment (IDE) that will keep all the windows from overlapping, color code your script, and let you click on tables to view them in actual tabular form.
Hope you try this out and it’s helpful to you! If you want to know how to add in a tweak you want, or if you’re getting an error and you can’t understand why, let me know! Do you like to graph differently in R? Let me know! You can comment here, email me, or find me on reddit as /u/misschedda.
I’d also love to see your graph if you made one using this code! Happy net worth growing!