# plot-browsing-shares.R
# Ilari Scheinin <firstname.lastname@helsinki.fi>
# MIT License

# This script reads operating system market share data from
# http://ilari.scheinin.fi/browsing-shares/data.txt
# and produces three plots from the data.

market.shares <- read.table("http://ilari.scheinin.fi/browsing-shares/data.txt", header=TRUE, sep="\t")
market.shares$Month <- as.Date(paste(market.shares$Month, "-01", sep=""))

png("windows.png")
plot(data.frame(market.shares$Month, 0), main="Windows", xlab="Month", ylab="Market Share", type="l", ylim=c(80, 100))
lines(market.shares[c("Month", "Windows")], col=1)
dev.off()

png("others.png")
plot(data.frame(market.shares$Month, 0), main="Other Operating Systems", xlab="Month", ylab="Market Share", type="n", ylim=c(0, 7))
lines(market.shares[c("Month", "Mac")], col=2)
lines(market.shares[c("Month", "Linux")], col=3)
lines(market.shares[c("Month", "Other.device")], col=1)
legend("topleft", inset=0.01, legend=c("Mac", "Linux", "Others"), fill=c(2:3, 1))
dev.off()

png("handhelds.png")
plot(data.frame(market.shares$Month, 0), main="Handheld Devices", xlab="Month", ylab="Market Share", type="n", ylim=c(0, 7))
lines(market.shares[c("Month", "iOS")], col=2)
lines(market.shares[c("Month", "Android")], col=3)
lines(market.shares[c("Month", "Java")], col=4)
lines(market.shares[c("Month", "Windows.Mobile")], col=5)
lines(market.shares[c("Month", "Symbian")], col=6)
lines(market.shares[c("Month", "BlackBerry")], col=7)
lines(market.shares[c("Month", "Other.handheld")], col=1)
legend("topleft", inset=0.01, legend=c("iOS", "Android", "Java", "Windows", "Symbian", "BlackBerry", "Others"), fill=c(2:7, 1))
dev.off()
