Get Started

Visualize your vector

Time to try something a bit different. So far, you have been programming in the script, and looking at your data by printing it out. For a more informative visualization, try a plot!

For this exercise, you will again be working with some Apple stock data. This time it contains the prices for all of December, 2016.

The plot() function is one of the many ways to create a graph from your data in R. Passing in a vector will add its values to the y-axis of the graph, and on the x-axis will be an index created from the order that your vector is in.

Inside of plot(), you can change the type of your graph using type =. The default is "p" for points, but you can also change it to "l" for line.

This is a part of the course

“Introduction to R for Finance”

View Course

Exercise instructions

apple_stock has already been defined, and everything has been set up for you. Try running the script line-by-line using Command + Enter on Mac or Control + Enter on Windows while clicked on each line.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Look at the data
apple_stock

# Plot the data points
plot(apple_stock)

# Plot the data as a line graph
plot(apple_stock, type = "l")
Edit and Run Code