library(readxl)
## Warning: package 'readxl' was built under R version 4.3.3
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.3
library(scatterplot3d)
library(wordcloud)
## Warning: package 'wordcloud' was built under R version 4.3.3
## Loading required package: RColorBrewer
library(treemap)
## Warning: package 'treemap' was built under R version 4.3.3
library(rworldmap)
## Warning: package 'rworldmap' was built under R version 4.3.3
## Loading required package: sp
## Warning: package 'sp' was built under R version 4.3.3
## ### Welcome to rworldmap ###
## For a short introduction type :   vignette('rworldmap')
forbes <- read_excel("C:/Users/b22fa/Desktop/programm/Forbes2000.xlsx")



treemap(forbes, index = "country", vSize = "marketvalue", title = "Улсуудын компануудын зах зээлийн түвшин")

treemap(forbes, index ="category", vSize = "sales", title = "Салбаруудын борлуулалтын үзүүлэлт")

country_table <- table(forbes$country)
top10country <- sort(country_table, decreasing = TRUE) [1:10]
print(top10country)
## 
##  United States          Japan United Kingdom        Germany         France 
##            751            316            137             65             63 
##         Canada    South Korea          Italy      Australia         Taiwan 
##             56             45             41             37             35
barplot(top10country, 
        col="darkblue", 
        main  ="Шилдэг 10 улс", 
        col.main="darkblue", 
        xlab="Улс", 
        ylab = "Forbes-д багтсан компани",
        border="blue")
grid(col = "skyblue", lty = "dotted", lwd = 0.5)
abline(h=2, col="blue")

topcategory <- aggregate(sales ~ category, data=forbes,sum)
categorytable <- table(topcategory)
topcategory <- topcategory[order(-topcategory$sales),][1:15,]
pie(topcategory$sales, labels=topcategory$category, main ="Борлуулалтаар тооцсон салбарын үзүүлэлтүүд")

plot(forbes$profits, forbes$marketvalue, main = "Ашиг болон зах зээлийн үнэлгээ", xlab = "Ашиг", ylab = "Зах зээлийн үнэлгээ", col = "orange")
abline(lm(marketvalue ~ profits, data = forbes), col = "red", lwd = 3)
grid(col = "darkgrey", lty = "dotted", lwd = 0.5)

wordcloud(forbes$name, freq = forbes$sales, max.words = 250, random.order = TRUE, colors = rainbow(50))
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : Tokyo
## Electric Power could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : Chubu
## Electric Power could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Nissan Motor could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Goldman Sachs Group could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : HSBC
## Group could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## ExxonMobil could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : Royal
## & Sun Alliance could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Procter & Gamble could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Generali Group could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Toyota Tsusho could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Unilever could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : Tyson
## Foods could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : JP
## Morgan Chase could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Telecom Italia could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Saint-Gobain could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Fannie Mae could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## ConAgra Foods could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Veolia Environnement could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : BP
## could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : Cisco
## Systems could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : SBC
## Communications could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Marubeni could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : Sears
## Roebuck could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Renault Group could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Honeywell could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : Ford
## Motor could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : EI du
## Pont de Nemours could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Johnson & Johnson could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Nestle could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Costco Wholesale could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## International Paper could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## AmerisourceBergen could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Barclays could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Repsol-YPF could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## ABN-Amro Holding could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Siemens Group could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Electronic Data Sys could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Ingram Micro could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Kansai Electric Power could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## General Electric could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Credit Suisse Group could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : Ahold
## could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Credit Agricole could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Compass Group could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Pfizer could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : JFE
## Holdings could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : E.ON
## could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : ENI
## could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Weyerhaeuser could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## ThyssenKrupp Group could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## General Motors could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : ABB
## Group could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : East
## Japan Railway could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## MetLife could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : Honda
## Motor could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## ConocoPhillips could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : Swiss
## Re Group could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## France Telecom could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Archer Daniels could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Albertsons could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Mitsubishi Heavy Inds could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : Norsk
## Hydro could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Lockheed Martin could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : RWE
## Group could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : CNP
## Assurances could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Ito-Yokado could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Wal-Mart Stores could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## United Technologies could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Hyundai Motor could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Itochu could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## American Intl Group could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : AXA
## Group could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : BT
## Group could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Zurich Financial Services could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Mitsubishi Motors could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : Home
## Depot could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : Royal
## Bank of Scotland could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Delphi could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Microsoft could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Berkshire Hathaway could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Verizon Commun could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Hitachi could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : Bank
## of America could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Wachovia could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Citigroup could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Prudential Financial could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Cardinal Health could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Hewlett-Packard could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Deutsche Telekom could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Novartis Group could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Vivendi Universal could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Johnson Controls could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : Fuji
## Photo Film could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Altria Group could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## American Express could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Mitsui & Co could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Nissho Iwai-Nichimen could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : Dow
## Chemical could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Matsushita Electric Indl could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Centrica could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : Legal
## & General Group could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Aventis could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : Sanyo
## Electric could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## GlaxoSmithKline could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## DaimlerChrysler could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## United Parcel Service could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Toshiba could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : China
## Petroleum & Chemical could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : News
## Corp could not be fit on page. It will not be plotted.

## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Kroger could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Walgreen could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Lowe`s Cos could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Safeway could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Nippon Mining could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : Suez
## Group could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Mizuho Financial could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : BASF
## Group could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : Time
## Warner could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : ING
## Group could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : Bayer
## Group could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Samsung Electronics could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Volkswagen Group could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : Metro
## AG could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Bristol-Myers Squibb could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : Royal
## Dutch/Shell Group could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : Total
## could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Northrop Grumman could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, : ENEL
## could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Peugeot Groupe could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Deutsche Post could not be fit on page. It will not be plotted.
## Warning in wordcloud(forbes$name, freq = forbes$sales, max.words = 250, :
## Nippon Oil could not be fit on page. It will not be plotted.
scatterplot3d(forbes$sales, forbes$profits, forbes$marketvalue, color = "orange", pch = 16, main = "Борлуулалт Зах зээлийн үнэлгээ Ашиг")

ggplot(forbes, aes(x = sales, y = profits)) + geom_bin2d() + scale_fill_gradient(low = "green", high = "red") + theme_minimal()
## Warning: Removed 5 rows containing non-finite outside the scale range
## (`stat_bin2d()`).

top10_companies <- forbes[order(-forbes$marketvalue), ][1:10, ]
ggplot(top10_companies, aes(x = reorder(name, marketvalue), y = marketvalue)) +
  geom_segment(aes(x = name, xend = name, y = 0, yend = marketvalue), color = "blue") +
  geom_point(color = "red", size = 4) +
  coord_flip() +
  theme_minimal() +
  labs(title = "Шилдэг 10 компани", x = "Компани", y = "Зах зээлийн үнэлгээ")

country_counts <- aggregate(rank ~ country, data = forbes, length)
world_map <- joinCountryData2Map(country_counts, joinCode = "NAME", nameJoinColumn = "country")
## 50 codes from your data successfully matched countries in the map
## 11 codes from your data failed to match with a country code in the map
## 194 codes from the map weren't represented in your data
mapCountryData(world_map, nameColumnToPlot = "rank", catMethod = "logFixedWidth", colourPalette = "heat",)  

ggplot(forbes, aes(x = sales, y = marketvalue, color = profits)) +
  geom_point(alpha = 1, size = 3) +
  theme_minimal() +
  scale_color_gradient(low = "blue", high = "yellow") +
  theme(panel.background = element_rect(fill = "black")) +
  labs(title = "Ашиг болон Зах зээлийн үнэлгээ", x = "Борлуулалт", y = "Зах зээлийн үнэлгээ")