ComeçarComece de graça

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.

Este exercício faz parte do curso

Introduction to R for Finance

Ver curso

Instruções do exercício

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.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# 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")
Editar e executar o código