Two time series grouped or stacked
In the first chapter, you learned how to use axis() to plot two lines on the same graphic with different Y scales. Should you want to compare them, however, you may find other kind of graphs to be more insightful. One solution is to plot both time series as barcharts. There are two types:
- Grouped barchart: for a single period, there are as many bars as time series
- Stacked bar chart: for each period, there is a single bar, and each time series is represented by a portion of the bar proportional to the value of the time series at this date (i.e. the total at each period adds up to 100%)
You are provided with a dataset (portfolio) containing the weights of stocks A (stocka) and B (stockb) in your portfolio for each month in 2016. You will use the barplot() function to create both types of charts.
Bu egzersiz
Visualizing Time Series Data in R
kursunun bir parçasıdırEgzersiz talimatları
- Plot a stacked barplot for
stockaandstockb. - Plot a grouped barplot for
stockaandstockbby settingbesideequal toTRUE.
Uygulamalı interaktif egzersiz
Bu örnek kodu tamamlayarak bu egzersizi bitirin.
# Plot stacked barplot
# Plot grouped barplot