Units: Average serving sizes per person Source: World Health Organisation, Global Information System on Alcohol and Health (GISAH), 2010

library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5     v purrr   0.3.4
## v tibble  3.1.4     v dplyr   1.0.7
## v tidyr   1.1.3     v stringr 1.4.0
## v readr   2.0.1     v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(readxl)
library(plotly)
## 
## 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(ggcleveland)
library(GGally)
## Registered S3 method overwritten by 'GGally':
##   method from   
##   +.gg   ggplot2
alcohol<-read.csv("alcohol-consumption.csv")


df <- na.omit(alcohol)


wine_p<- read.csv("wine_price.csv")
spirit_p<- read.csv("spirit_price.csv")
beer_p<- read.csv("beer_price.csv")


names(wine_p)[names(wine_p) == "ï..Country"] <- "Country"
names(beer_p)[names(beer_p) == "ï..Location"] <- "Country"


# Average Price per 500ml Beer in USD
#beer_p
# Average Price per 75000ml Wine in USD
#wine_p
# Average Price per 500ml Spirit in USD
#spirit_p

## https://www.who.int/data/gho/data/themes/topics/topic-details/GHO/economic-aspects





beer <- merge(df,beer_p, by=c("Country", "Country")) 

wine<-merge(df,wine_p, by=c("Country", "Country")) 

spirit<- merge(df,spirit_p, by=c("Country", "Country")) 
library(ggplot2)
dist1 <- ggplot(df) +
  geom_density(aes(x = df$beer_servings, fill = "Beer"), alpha = 0.25) +
  geom_density(aes(x = df$wine_servings, fill = "Wine"), alpha = 0.25) +
   geom_density(aes(x = df$spirit_servings, fill = "Spirit"), alpha = 0.25)+
  
  ggtitle("Beer, wine & Spirit Conspumtion Distribution") +
  xlab("Beer | Wine | Spirit") + ylab("Density" )
ggplotly(dist1)
dist2<- ggplot(df) +
  geom_density(aes(x = df$total_litres_of_pure_alcohol), alpha = 0.25,)+
  ggtitle("Total Alcohol Distribution") +
  xlab("Total Alcohol in Litres") + ylab("Density" )

ggplotly(dist2)

Boxplot

library(plotly)

b<- plot_ly(df, x = ~continent, y = ~wine_servings )%>%
  add_boxplot(color = ~continent) %>%
  layout(yaxis = list(title = "Wine Servings"))


a<- plot_ly(df, x = ~continent, y = ~beer_servings )%>%
  add_boxplot(color = ~continent) %>%
  layout(yaxis = list(title = "Beer Servings"))


subplot(a,b, nrows=2)
g <- ggplot(df, aes(continent))
g <- g + geom_boxplot(aes(y=beer_servings), colour="red")
g <- g + geom_boxplot(aes(y=wine_servings), colour="green")
g

fig <- plot_ly(df , x = ~continent, y = ~beer_servings, type = 'box', color=~continent) %>%
  add_trace(df, x = ~continent, y = ~wine_servings, type = 'box')

fig
ggplot(data = df) +
  geom_point(mapping = aes(x = continent, y = beer_servings))

ggplot(data = df, mapping = aes(x = log10(population), y = beer_servings)) +
  geom_point(aes(size = beer_servings), alpha = 1/3) +
  geom_smooth(method = loess, se = FALSE)
## `geom_smooth()` using formula 'y ~ x'

Distribution

ggplot(alcohol) + geom_density(aes(x = beer_servings))

dis_plot <- ggplot(df, aes(x = continent, y = population)) + geom_bar(stat = "identity", fill = "light blue")
dis_plot

Mapbox

Mapview

Beer Price over the countries

# install.packages("mapview")
library(mapview)

mapview(df, xcol = "longitude", ycol = "latitude", zcol = c("beer_servings", "total_litres_of_pure_alcohol") , crs = 4269, grid = FALSE)
map2<- mapview(beer, xcol = "longitude", ycol = "latitude", zcol = c("beer_price", "beer_servings") , crs = 4269, grid = FALSE)
map2

Co-Relation Between Price and Servings

# install.packages("ggpubr")

library("ggpubr")
ggscatter(beer, x = "beer_price", y = "beer_servings", 
          add = "reg.line", conf.int = TRUE, 
          cor.coef = TRUE, cor.method = "pearson",
          xlab = "Beer Price", ylab = "Beer Servings")
## `geom_smooth()` using formula 'y ~ x'

ggscatter(wine, x = "wine_price", y = "wine_servings", 
          add = "reg.line", conf.int = TRUE, 
          cor.coef = TRUE, cor.method = "pearson",
          xlab = "Wine Price", ylab = "Wine Servings")
## `geom_smooth()` using formula 'y ~ x'

ggscatter(spirit, x = "spirit_price", y = "spirit_servings", 
          add = "reg.line", conf.int = TRUE, 
          cor.coef = TRUE, cor.method = "pearson",
          xlab = "Spirit Price", ylab = "Spirit Servings")
## `geom_smooth()` using formula 'y ~ x'

lmprice_servings = lm(beer_servings~beer_price, data= beer) #Create the linear regression
summary(lmprice_servings) #Review the results
## 
## Call:
## lm(formula = beer_servings ~ beer_price, data = beer)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -129.15  -86.59  -31.50   85.68  272.28 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   98.997     13.652   7.251 2.56e-11 ***
## beer_price     4.215      5.332   0.791    0.431    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 101.1 on 140 degrees of freedom
## Multiple R-squared:  0.004444,   Adjusted R-squared:  -0.002667 
## F-statistic: 0.625 on 1 and 140 DF,  p-value: 0.4305

Corleation

library(GGally)
 
# Create data 
data <- data.frame( beer$beer_servings, beer$beer_price) 

 ggpairs(data, title="correlogram: Beer Price vs. Beer Servings")