My first ‘R’ plot

May 16, 2011

(This article was first published on Interpretations of technorealism, and kindly contributed to R-bloggers)

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. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)