0

First, trying to show the relationship between the 60 day returns and tickers AAPL & TSLA with boxplots. I was expecting a boxplot for APPL and for TSLA, it is only showing me APPL.

ggplot(dailyPrice[ticker %in% c('AAPL','TSLA') & is.finite(ey)], aes(y=ret60,x=ticker)) + 
  geom_boxplot()

Second, trying to show the relationship between date and ey for APPL and TSLA. I was expecting the line graph to have two lines on same graph, but it is only showing one.

ggplot(dailyPrice[ticker =='AAPL' & is.finite(ey)],aes(x=date ,y=ey)) + 
  geom_line(color='blue') + 
  geom_line(data=dailyPrice[ticker =='TSLA' & is.finite(ey)],aes(x=date ,y =ey),color='red')

zephryl
  • 14,633
  • 3
  • 11
  • 30
ceek
  • 1
  • 3
    Please add some data. Like using `dput()`. – TarJae Nov 25 '22 at 16:02
  • 3
    Check your data. There are most likely no observations for `ticker =='TSLA' & is.finite(ey)`. If you need more help I would suggest to provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including a snippet of your data or some fake data. – stefan Nov 25 '22 at 16:02
  • 1
    I suggest letting `ggplot2` aesthetics handle colors for you, there are several benefits on top of code simplification. Try: `ggplot(dailyPrice[ticker %in% c("AAPL", "TSLA") & is.finite(ey),], aes(date, ey, color=ticker)) + geom_line()` ... and if you really want those colors, then add `+ scale_color_manual(values=c(AAPL="blue", TSLA="red"))`. – r2evans Nov 25 '22 at 19:39

0 Answers0