Advertisement
friedmusic

A11

Feb 26th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.33 KB | None | 0 0
  1. ```{r A11}
  2. library(tidyverse)
  3. library(janitor)
  4. library(googleVis)
  5. #Read the file <http://www.richardtwatson.com/data/InternetCompanies.csv> containing data about Internet companies.
  6. #warnings setting off
  7. oldw <- getOption("warn")
  8. options(warn = -1)
  9.  
  10. url<-'http://www.richardtwatson.com/data/InternetCompanies.csv'
  11. w<-read_csv(url)
  12.  
  13. #Cleaning the file
  14. w$MarketCap<-str_extract(w$MarketCap,"[\\d,.]+")%>%as.numeric()
  15. w$Cash<-str_extract(w$Cash,"[\\d,.]+")%>%as.numeric()
  16. w$Revenue<-str_extract(w$Revenue,"[\\d,.]+")%>%as.numeric()
  17. w<-w[1:5,]
  18. w
  19.   # Use ggplot2 to create a point graph of market capitalization versus revenue for the five largest companies by market capitialization and label each point with the company's name.
  20. ggplot(w, aes(MarketCap, Revenue,label=Company)) + geom_point(color='salmon') +
  21. xlab('Market Capitalization') + ylab('Revenue') + ylim(0, 300) +
  22. geom_text(aes(label=Company), vjust= 2)
  23.  
  24. w
  25. #Use googleVis to create a bubble chart for the same set of companies.
  26. Bubble <- gvisBubbleChart(w, idvar="Company",
  27.                           xvar="MarketCap", yvar="Revenue",
  28.                           sizevar="Cash", colorvar = "Country"
  29.                           )
  30.  
  31. plot(Bubble)
  32. #Submit a markdown file with all code and a screen shot of the bubble chart.
  33.  
  34. #normal warning setting
  35. options(warn = oldw)
  36. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement