---
title: "Where are the users from?"
author: "Eryk Walczak"
date: "5 October 2016"
output: html_document
---

```{r, warning=FALSE, message=FALSE}
library(dplyr)
library(readr)
```

## Load the file


```{r}
pvs <- read_csv("../input/page_views_sample.csv")
```

## Data munging

You can also embed plots, for example:

```{r}
# display the structure
str(pvs)

# extract the country code
pvs$country <- substr(pvs$geo_location, 1, 2)

# group by country and count the number of views
pvs_country <- pvs %>% group_by(country) %>% summarise(Volume = n()) %>% arrange(desc(Volume))

# display the df
pvs_country
```

## Bar chart

```{r, warning=FALSE, message=FALSE}
library(plotly)

plot_ly(x = pvs_country$country,
        y = pvs_country$Volume,
        type = "bar")
```

This shows that the vast majority of traffic comes from the US, followed by Canada, Great Britain, and Australia.