Site icon R-bloggers

My first ‘R’ plot

[This article was first published on Interpretations of technorealism, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Started learning ‘R’.
My first attempt was to plot data from Forbes 1000 list (refer to the exercise posted by Prasoon sharma)

Here is a bubble chart showing Forbes top 25 companies by Market Capitalization

Source code:
## read the csv file
FORBES.DF <- read.csv("forbes2000list_for_2011.csv")

## assign titles
names(FORBES.DF)<- c("Rank", "Company", "Country", "Industry", "Sales", "Profits", "Assets", "MarketCap")

## create a smaller vector
Forbes100ByMC <- FORBES.DF[order(-FORBES.DF$MarketCap),][1:100,]
Forbes25 <- Forbes100ByMC[1:25, ]

## plot the bubble chart using 'symbols'
radius <- sqrt(Forbes25$MarketCap/pi)
sales <- as.numeric(as.character(Forbes25$Sales))
profits <- as.numeric(as.character(Forbes25$Profits))

symbols(sales, profits, circles=radius, inches=0.9, fg="white", bg="light blue", xlab="Sales($'Billions)", ylab="Profits($'Billions)", main="Forbes 25 By Market Capitalization", xlim=c(min(range(sales))-50, max(range(sales))+50), ylim=c(min(range(profits))-2, max(range(profits))+2))
## print the names of companies
text(sales, profits, Forbes25$Company, cex=0.6, col="dark red") 
 
Any feedback toward writting better ‘R’ code is welcome.

To leave a comment for the author, please follow the link and comment on their blog: Interpretations of technorealism.

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.