# My first ‘R’ plot

May 16, 2011
By

(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 fileFORBES.DF <- read.csv("forbes2000list_for_2011.csv")## assign titlesnames(FORBES.DF)<- c("Rank", "Company", "Country", "Industry", "Sales", "Profits", "Assets", "MarketCap")## create a smaller vectorForbes100ByMC <- 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 companiestext(sales, profits, Forbes25\$Company, cex=0.6, col="dark red") `

Any feedback toward writting better ‘R’ code is welcome.

R-bloggers.com 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...