Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have this data already in long format suitable for ggplot 2 . I am using this R code to plot cumulative returns of all

I have this data already in long format suitable for ggplot2. I am using this R code to plot cumulative returns of all stocks in 1 graph. Can you provide the R code. Mine keeps giving error "geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?" WHy?
ggplot(merged_data_long, aes(x = Date, y = Cumulative_Return, color = Stock))+
geom_line()+
labs(title = "Cumulative Returns of AAPL and TSLA",
x = "Date",
y = "Cumulative Returns",
color = "Stock")+
theme_minimal()te Stock Cumulative_Return
Data below:
2015-02-27 AAPL 0.105252332
2015-02-27 TSLA -0.001276991
2015-03-31 AAPL 0.070578632
2015-03-31 TSLA -0.072838823
2015-04-30 AAPL 0.076773467
2015-04-30 TSLA 0.110265248
2015-05-29 AAPL 0.130565242
2015-05-29 TSLA 0.231827110
2015-06-30 AAPL 0.088477075
2015-06-30 TSLA 0.317583607
2015-07-31 AAPL 0.052637118
2015-07-31 TSLA 0.307220127
2015-08-31 AAPL -0.012049551
2015-08-31 TSLA 0.223280999
2015-09-30 AAPL -0.033602889
2015-09-30 TSLA 0.220039303
2015-10-30 AAPL 0.047003010
2015-10-30 TSLA 0.016355609
2015-11-30 AAPL 0.045945104
2015-11-30 TSLA 0.130943095
2015-12-31 AAPL -0.069347331
2015-12-31 TSLA 0.178831155
2016-01-29 AAPL -0.139371937
2016-01-29 TSLA -0.060903677
2016-02-29 AAPL -0.135436453
2016-02-29 TSLA -0.057318265
2016-03-31 AAPL -0.025454898
2016-03-31 TSLA 0.128536379
2016-04-29 AAPL -0.161814314
2016-04-29 TSLA 0.182514793
2016-10-31 AAPL 0.03928824
2016-10-31 TSLA -0.02883099
2016-11-30 AAPL 0.02246611
2016-11-30 TSLA -0.06974453
2016-12-30 AAPL 0.07149890
2016-12-30 TSLA 0.04955802
2017-01-31 AAPL 0.12265923
2017-01-31 TSLA 0.23737730
2017-02-28 AAPL 0.27850483
2017-02-28 TSLA 0.22784880
2017-03-31 AAPL 0.34075469
2017-03-31 TSLA 0.36689593
2017-04-28 AAPL 0.34066172
2017-04-28 TSLA 0.54258354
2017-05-31 AAPL 0.43785011
2017-05-31 TSLA 0.67490178
2017-06-30 AAPL 0.35558538
2017-06-30 TSLA 0.77608054
2017-07-31 AAPL 0.39991809
2017-07-31 TSLA 0.58875253
2017-08-31 AAPL 0.55601880
2017-08-31 TSLA 0.74803549
2017-09-29 AAPL 0.46227750
2017-09-29 TSLA 0.67534386
2017-10-31 AAPL 0.60383714
2017-10-31 TSLA 0.62833989
2017-11-30 AAPL 0.64269510
2017-11-30 TSLA 0.51694506
2017-12-29 AAPL 0.61765110
2017-12-29 TSLA 0.52922399

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions