A fancy stock chart (2)
In this exercise, you will add a legend to the chart that you just created containing the name of the companies and the dates and values of the latest dividends.
Fill in the pre-written code with the following variables containing the dividend values and dates for both companies:
citi_div_valueciti_div_datemicro_div_valuemicro_div_date
Recall that the default color of a plotted line is black, and that the values for legend, col, and lty in legend() should be set to vectors of the same length as the number of time series plotted in your chart.
If you can't see all of the legend, try making the chart full screen after you plot it. Let's make our chart even fancier!
Cet exercice fait partie du cours
Visualizing Time Series Data in R
Instructions
- Create the same plot as in the previous exercise (this has been done for you)
- Use the pre-loaded variables above to create the strings,
microandciti, to be used in the legend "Microsoft div of $0.39 on 15 Nov. 2016""Citigroup div of $0.16 on 13 Nov. 2016"- Create the legend on the bottom right corner of the chart using the
microandcitistrings you just created for the text, appropriate colors for the labels, and regular lines
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# Same plot as the previous exercise
plot(data$microsoft, main = "Dividend date and amount")
lines(data$citigroup, col = "orange", lwd = 2)
axis(side = 4, at = pretty(data$citigroup), col = "orange")
# Create the two legend strings
micro <- paste0("Microsoft div. of ", ___," on ", ___)
citi <- paste0("Citigroup div. of ", ___," on ", ___)
# Create the legend in the bottom right corner
legend(x = ___, legend = c(___, ___), col = c(___, ___), lty = c(___, ___))