---
title: "SuperWorld Plot Sales"
output:
flexdashboard::flex_dashboard:
orientation: rows
social: menu
source_code: embed
---
Inputs {.sidebar}
-------------------------------------
More than half of plots sold are located in the United States, most notably in New York, California, Texas, and Nevada
```{r setup, include=FALSE}
library(flexdashboard)
library(leaflet)
library(htmltools)
library(leaflet.extras)
library(datasets)
library(sf)
library(crosstalk)
library(tidyverse)
library(reactable)
library(rnaturalearth)
library(rnaturalearthdata)
library(plotly)
load("~/SuperWorld/dashboard1_workspace.RData")
sold = read_csv("C:/Users/tzipo/SuperWorld_Plot_Recommendation/data/plots_sold.csv")
# plots_sold = unique(merge(sold, plots, by = c("lat", "lon"), all.x = TRUE))
#
#
# us_address = plots_sold[which(plots_sold$code == "US"),]$address
#
# state = c()
# for (i in 1:length(us_address)){
# add = unlist(str_split(us_address[i], pattern = ", "))
# state = c(state, add[length(add) - 1])
# }
# for (i in 1:length(state)){
# if (state[i] == "New Jersey") {
# state[i] = "NJ"
# }
# else if (state[i] == "New York") {
# state[i] = "NY"
# }
# else if (state[i] == "District of Columbia") {
# state[i] = "DC"
# }
# else {
# add = unlist(str_split(state[i], pattern = " "))
# state[i] = add[1]
# }
# }
#
# state = ifelse(state == "Louisiana", "LA",
# ifelse(state == "California", "CA",
# ifelse(state == "Missouri", "MO",
# ifelse(state == "Illinois", "IL",
# ifelse(state == "Utah", "UT", state)))))
```
Row {data-height=600}
-------------------------------------
### Plots Sold Across the World
```{r}
# world = ne_countries(scale = "medium", returnclass = "sf")
# df = st_sf(merge(plots_sold, world, by.x = "code", by.y = "iso_a2", all.x = TRUE, all.y = TRUE, returnclass = "sf"))
#
#
# df = df %>%
# group_by(country) %>%
# summarise(sold = n()) %>%
# mutate(sold = ifelse(sold == 443, 0, sold)) %>%
# ggplot() +
# geom_sf(aes(fill = log(sold)))
ggplotly(df)
```
Row
-------------------------------------
### Plot Locations
```{r}
leaflet(plots_sold) %>%
addTiles() %>%
addCircles(lng = ~lon, lat = ~lat) %>%
setView(lat = 37.0902, lng = -95.7129, zoom = 4)
```
### Plots Sold in the US
```{r}
library(usmap)
# state_data = data.frame(state) %>%
# group_by(state) %>%
# summarise(sold = n())
#
# us = plot_usmap(data = state_data, values = "sold", regions = "states") +
# theme(legend.position = "right") +
# scale_fill_continuous(name = "Plots Sold")
ggplotly(us)
```