Apple Compared to Others with ggthemes
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
For a happy person delightfully concentrated in Apple, I wanted to show Apple’s performance versus Microsoft and Cisco in decades 1(1990-2000) and 2 (2000-2012). I thought this would give me a good chance to try out the very interesting work being done at https://github.com/jrnold/ggthemes.
![]() |
From TimelyPortfolio |
Just as a reference, my general goto chart is theEconomist set from latticeExtra. Here is how it would look with that method. I think it is still my favorite.
![]() |
From TimelyPortfolio |
For another chart since 2003 prepared by the far more capable at the Wall Street Journal, see Why Microsoft Beats Apple hat tip from Stock Picking Matters: Apple v Microsoft from The Big Picture by Global Macro Monitor with a hat tip from Jason Zweig.
My best guess in terms of the debate is some other company will resoundingly beat both Microsoft and Apple over the next decade.
require(ggplot2) | |
#to get ggthemes from jrnold github if you have not installed | |
#require(devtools) | |
#install_github("ggthemes","jrnold") | |
require(ggthemes) | |
require(reshape2) | |
require(directlabels) | |
require(quantmod) | |
require(PerformanceAnalytics) | |
tckrs <- c("CSCO","MSFT","AAPL","^GSPC") | |
getSymbols(tckrs,from="1990-01-01") | |
prices <- na.omit(merge(CSCO[,6],MSFT[,6],AAPL[,6],GSPC[,6])) | |
colnames(prices) <- c("Cisco","Microsoft","Apple","SP500") | |
returns <- prices/lag(prices) - 1 | |
returns[1,] <- 0 | |
cumul <- cumprod(returns+1) | |
cumul.df <- as.data.frame(cbind(index(cumul),coredata(cumul))) | |
cumul.melt <- melt(cumul.df,id.vars=1) | |
colnames(cumul.melt) <- c("Date","Stock","Cumul") | |
cumul.melt[,"Date"] <- as.Date(cumul.melt[,"Date"]) | |
direct.label( | |
ggplot(cumul.melt, aes(x=Date,y=log(Cumul),colour=Stock)) + | |
geom_line() + | |
theme_economist() + #if you want to play try theme_wsj() or theme_few() | |
scale_colour_economist() + | |
ggtitle("Apple Compared to Others Since 1990") | |
, list(last.bumpup,hjust=0.45,cex=0.65)) | |
ggsave(plot=last_plot(),file="apple.png",width=6,height=4) | |
#for reference I will use my old favorite theEconomist from latticeExtra | |
require(latticeExtra) | |
direct.label( | |
asTheEconomist(xyplot(log(Cumul)~Date,data=cumul.melt,groups=Stock, | |
main="Apple Compared to Microsoft and Cisco Since 1990") | |
) | |
, list(last.bumpup,hjust=0.25,cex=1)) | |
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.