Using R & ggplot2 For My Research Project

(This is my first post via RMarkdown, which is a way of communicating code and graphs from R in a clean HTML format.)

One of my three-credit courses this semester is a Directed Study in which I work on a research project and hopefully come up with a report and some cool results . After taking a Computer Simulation Systems class last semester (with ARENA Simulation Software) and familiarizing myself with concepts in simulation and optimization of complex systems, I was fortunate enough to get the opportunity to work on another independent simulation project this semester.

The system I'm studying is a commercial parking lot with 100 spots that earns money in two ways: by selling a guaranteed parking space for a monthly fee, or by charging an hourly rate for customers who show up without a monthly pass. The goal of the study is to come up with a flexible management strategy for this system that ultimately maximizes profit.

The monthly parking pass is designed to, in exchange for a flat monthly fee, guarantee a parking space each day for subscribers. We'll call these subscribers “monthly” customers. Part of the management strategy involves determining how many spaces in the lot should be reserved exclusively for these monthly subscribers. We could reserve one for every subscriber, but that would probably leave some profit on the table as we don't expect these monthly passholders to show up every single day. Still, anytime a monthly subscriber is turned away due to a lack of spots, our company incurs a hefty expense since we failed on our end of the deal.

On the other hand, cars that show up to the lot without a monthly pass aren't guaranteed a parking spot. If a car shows up when the lot's unreserved spots are full, that car is turned away from the lot, and our simulation adds this to a statistic called “Unrealized Profit”. This group of customers are called the “hourly” customers.

Part of the reason we use simulations is to see how the entire system's behavior changes when we adjust only one parameter. If we want to see how the amount of monthly parking spots we reserve impacts our net profit, we can do that by holding everything fixed and running simulations for different numbers of reserved spots. When we get the results, we make plots to observe and understand the behavior.

Anyway, the point of this post is to make some cool plots in R. In order to build the plots, I turned to the ggplot2 library. While making simple plots in R isn't difficult, ggplot2 allows us to make beautiful plots with custom colors, fonts, and other nifty features.

After running our simulation and gathering the data, I opened it in R with the following code:

The first plot I developed is exactly what I just described above: we are comparing the relationship between Monthly Spots Reserved and Net Profit, while also varying the cost (Monthly Turnaway Cost) we incur for turning away monthly subscribers to see if that has any impact.

Here is the code, followed by the plot:

plot of chunk unnamed-chunk-2

As you can see, when we have a greater number of Monthly Spots Reserved, the Monthly Turnaway Cost doesn't have much of an impact on our Net Profit. However, when we reserve fewer spots, more and more monthly customers get turned away, increasing the impact that Monthly Turnaway Cost has on our profits. When the Monthly Turnaway Cost is $150, limiting the number of Monthly Spots Reserved looks like a terrible idea. However, when the Monthly Turnaway Cost is only $25, it becomes less of an issue. Of course, the business reality here is that when a monthly customer shows up to no parking spot, that's on us, so we probably want to pay more attention to the lines associated with larger Monthly Turnaway Costs.

The next plot will show the same thing, but instead of adjusting Monthly Spots Reserved, we keep that fixed and adjust the Hourly Arrival Rate, which describes how often hourly customers generally show up to the lot.

plot of chunk unnamed-chunk-3

When the Hourly Arrival Rate is small, fewer hourly customers show up to the parking lot, resulting in more spots available for the monthly subscribers and, ultimately, fewer monthly turnaways. However, when the Hourly Arrival Rate increases, there is less room for incoming monthly subscribers should all of the Monthly Spots Reserved be occupied, ultimately resulting in more monthly turnaways digging into our profits.

The ggplot2 package is great for adding artistic expression and personality to your reports and data visualizations. Visually appealing charts can go a long way in telling an effective story with your data.

One thought on “Using R & ggplot2 For My Research Project

  1. […] I can use coding skills to visualize data. […]

Leave a Reply

Your email address will not be published. Required fields are marked *