library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
## Registered S3 methods overwritten by 'ggplot2':
## method from
## [.quosures rlang
## c.quosures rlang
## print.quosures rlang
library(plotly)
## Warning: package 'plotly' was built under R version 3.6.1
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(tidyverse)
## -- Attaching packages ------------------------------------------------------- tidyverse 1.2.1 --
## v tibble 2.1.3 v purrr 0.3.2
## v tidyr 0.8.3 v stringr 1.4.0
## v readr 1.3.1 v forcats 0.4.0
## -- Conflicts ---------------------------------------------------------- tidyverse_conflicts() --
## x plotly::filter() masks dplyr::filter(), stats::filter()
## x dplyr::lag() masks stats::lag()
library(readr)
library(scales)
##
## Attaching package: 'scales'
## The following object is masked from 'package:purrr':
##
## discard
## The following object is masked from 'package:readr':
##
## col_factor
library(portfolio)
## Warning: package 'portfolio' was built under R version 3.6.1
## Loading required package: grid
## Loading required package: lattice
## Loading required package: nlme
##
## Attaching package: 'nlme'
## The following object is masked from 'package:dplyr':
##
## collapse
library(rnaturalearth)
## Warning: package 'rnaturalearth' was built under R version 3.6.1
library(rgeos)
## Warning: package 'rgeos' was built under R version 3.6.1
## Loading required package: sp
## rgeos version: 0.4-3, (SVN revision 595)
## GEOS runtime version: 3.6.1-CAPI-1.10.1
## Linking to sp version: 1.3-1
## Polygon checking: TRUE
library(gapminder)
## Warning: package 'gapminder' was built under R version 3.6.1
library(RColorBrewer)
technology1 <- read_csv(file = "TechnologyIndex.csv")
## Parsed with column specification:
## cols(
## Rank = col_double(),
## country = col_character(),
## iPhone = col_character(),
## Android = col_character(),
## MacBook = col_character(),
## WindowsPowered = col_character(),
## PS4 = col_character(),
## XboxOne = col_character(),
## iPadMini = col_character(),
## Samsungtablet = col_character(),
## `40inchSmartTV` = col_character(),
## AppleWatch = col_character(),
## BrandHeadphone = col_character(),
## HardDrive2TB = col_character(),
## PortableCharger = col_character(),
## Printer = col_character()
## )
Remove row 72 - Venezuela - due to confusion with a huge gap between amounts. These amounts are due to an economical crisis in Venezuela and we are taking it out since it is an outlier.
str(technology1)
## Classes 'spec_tbl_df', 'tbl_df', 'tbl' and 'data.frame': 72 obs. of 16 variables:
## $ Rank : num 1 2 3 4 5 6 7 8 9 10 ...
## $ country : chr "Kuwait" "Saudi Arabia" "Malaysia" "Canada" ...
## $ iPhone : chr "$641.50" "$513.86" "$532.06" "$555.25" ...
## $ Android : chr "$539.18" "$699.61" "$631.66" "$625.04" ...
## $ MacBook : chr "$795.38" "$1,054.98" "$1,010.31" "$1,118.10" ...
## $ WindowsPowered : chr "$528.34" "$686.88" "$1,022.67" "$1,081.40" ...
## $ PS4 : chr "$315.83" "$317.86" "$299.83" "$274.25" ...
## $ XboxOne : chr "$418.50" "$254.24" "$355.47" "$233.14" ...
## $ iPadMini : chr "$242.90" "$380.47" "$232.87" "$237.34" ...
## $ Samsungtablet : chr "$250.98" "$152.44" "$354.99" "$392.89" ...
## $ 40inchSmartTV : chr "$383.60" "$406.93" "$324.87" "$364.30" ...
## $ AppleWatch : chr "$242.90" "$381.48" "$248.43" "$259.21" ...
## $ BrandHeadphone : chr "$196.95" "$338.22" "$175.48" "$159.71" ...
## $ HardDrive2TB : chr "$89.03" "$114.27" "$116.16" "$87.12" ...
## $ PortableCharger: chr "$2.44" "$4.83" "$11.41" "$9.24" ...
## $ Printer : chr "$52.36" "$30.03" "$108.69" "$57.13" ...
## - attr(*, "spec")=
## .. cols(
## .. Rank = col_double(),
## .. country = col_character(),
## .. iPhone = col_character(),
## .. Android = col_character(),
## .. MacBook = col_character(),
## .. WindowsPowered = col_character(),
## .. PS4 = col_character(),
## .. XboxOne = col_character(),
## .. iPadMini = col_character(),
## .. Samsungtablet = col_character(),
## .. `40inchSmartTV` = col_character(),
## .. AppleWatch = col_character(),
## .. BrandHeadphone = col_character(),
## .. HardDrive2TB = col_character(),
## .. PortableCharger = col_character(),
## .. Printer = col_character()
## .. )
head(technology1, 3)
## # A tibble: 3 x 16
## Rank country iPhone Android MacBook WindowsPowered PS4 XboxOne
## <dbl> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
## 1 1 Kuwait $641.~ $539.18 $795.38 $528.34 $315~ $418.50
## 2 2 Saudi ~ $513.~ $699.61 $1,054~ $686.88 $317~ $254.24
## 3 3 Malays~ $532.~ $631.66 $1,010~ $1,022.67 $299~ $355.47
## # ... with 8 more variables: iPadMini <chr>, Samsungtablet <chr>,
## # `40inchSmartTV` <chr>, AppleWatch <chr>, BrandHeadphone <chr>,
## # HardDrive2TB <chr>, PortableCharger <chr>, Printer <chr>
tail(technology1, 4)
## # A tibble: 4 x 16
## Rank country iPhone Android MacBook WindowsPowered PS4 XboxOne
## <dbl> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
## 1 69 Brazil $843.~ $948.74 $3,390~ $564.91 $565~ $425.09
## 2 70 Brunei $764.~ $856.47 $2,326~ $1,545.52 $562~ $737.90
## 3 71 Angola $401.~ $2,641~ $1,001~ $1,574.17 $868~ $528.11
## 4 72 Venezu~ $97,8~ $78,05~ $176,0~ $35,941.09 $56,~ $37,07~
## # ... with 8 more variables: iPadMini <chr>, Samsungtablet <chr>,
## # `40inchSmartTV` <chr>, AppleWatch <chr>, BrandHeadphone <chr>,
## # HardDrive2TB <chr>, PortableCharger <chr>, Printer <chr>
technology1[72, ]
## # A tibble: 1 x 16
## Rank country iPhone Android MacBook WindowsPowered PS4 XboxOne
## <dbl> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
## 1 72 Venezu~ $97,8~ $78,05~ $176,0~ $35,941.09 $56,~ $37,07~
## # ... with 8 more variables: iPadMini <chr>, Samsungtablet <chr>,
## # `40inchSmartTV` <chr>, AppleWatch <chr>, BrandHeadphone <chr>,
## # HardDrive2TB <chr>, PortableCharger <chr>, Printer <chr>
technology <- technology1[-72, ]
tail(technology, 4)
## # A tibble: 4 x 16
## Rank country iPhone Android MacBook WindowsPowered PS4 XboxOne
## <dbl> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
## 1 68 Guatem~ $889.~ $591.31 $1,525~ $2,055.53 $535~ $341.96
## 2 69 Brazil $843.~ $948.74 $3,390~ $564.91 $565~ $425.09
## 3 70 Brunei $764.~ $856.47 $2,326~ $1,545.52 $562~ $737.90
## 4 71 Angola $401.~ $2,641~ $1,001~ $1,574.17 $868~ $528.11
## # ... with 8 more variables: iPadMini <chr>, Samsungtablet <chr>,
## # `40inchSmartTV` <chr>, AppleWatch <chr>, BrandHeadphone <chr>,
## # HardDrive2TB <chr>, PortableCharger <chr>, Printer <chr>
Bar Plot
We only want to focus on the first fifteen rows of our data, the cheapest fifteen countries. We’re also showing no ranking and only the iPhone price to see a trend of one product
firstFifteen <- filter(
technology,
technology$Rank <= 15
)
technologystack <- table(
firstFifteen$country,
firstFifteen$iPhone
)
ggplot(
firstFifteen,
aes(fill=country,
y=iPhone,
x=country)
) +
ylab("iPhone Price") +
ggtitle("Lowest Technology Price in 2016: First 15 Countries",
subtitle = "Device: iPhone") +
ylab("Price") +
geom_bar(position="dodge",
stat="identity"
) +
theme(axis.text.x = element_text(angle=50, hjust = 0.9))

Bubble Chart
We wanted to show 3 variables at the same time here, country, rank, and price and this bubble chart was a way to do so. It has a legend showing rank (color of numbers and size of bubbles)
techbubble <- firstFifteen
techbubble$country <- as.factor(techbubble$country)
head(firstFifteen[, "Samsungtablet"], 4)
## # A tibble: 4 x 1
## Samsungtablet
## <chr>
## 1 $250.98
## 2 $152.44
## 3 $354.99
## 4 $392.89
ggplot(firstFifteen,
aes(x = country,
y = Samsungtablet,
label = Rank,
color = Rank)
) +
xlab("Country") +
ylab("Price") +
geom_point(
aes(size = Rank),
color="orange",
) +
geom_text(
aes(x = country,
y = Samsungtablet,
label = Rank,
color = Rank),
size=4
) +
ggtitle("Lowest Technology Price 2016: First 15 Countries",
subtitle = "Device: Samsung Tablet"
) +
scale_size(range = c(0.5, 10)) +
theme_bw() +
theme(legend.position = "right") +
theme(plot.background = element_rect(fill = "lightgreen")) +
theme(axis.text.x = element_text(angle=90, hjust=0.95, vjust=0.5)
)
