Dyanmic Assignment

Author

GABA FOLLY NAPO

library(ggplot2)
library(plotly)
library(htmlwidgets)
library(dygraphs)
library(dplyr)
library(lubridate, warn.conflicts = FALSE)
library(anytime)
library(xts)

Description of the data and data source

For this assignment we use the data produes by the National Association of Realtors (NAR). NAR produces housing statistics on the national, regional, and metro-market level where data is available. we use the national historical data (view US data) on https://www.realtor.com/research/data/

what you want to convey in the figure

Through the figure we want to show how the median listing price and the median listing square feet change monthly from 2017 to 2022 in the united states.

Functionality and formatting put into the figure and why

package dygraphs is used to create an interactive graph. the functionality dyRangeSelector with no specification of window and dyOptions (stackedGraph =TRUE) to stack series on top of one another rather than drawing them independently. we only formatting the date in the standard form yyyy-mm-dd by using anydate in the package anytime and also as.Date to have the class equal to date.

Those functionality and formatting were used, because we have and interactive graph, we can mouse over to highlight individual values

Upload Date and formatting the date

library(tidyverse)
house=read.csv("C:/Users/L/OneDrive/Bureau/STAA 566/Dynamic Figure/RDC_Inventory_Core_Metrics_Country_History.csv",header = TRUE)
house=house%>% rename(Date=month_date_yyyymm)
house$Date=anydate(house$Date)
house$Date=as.Date(house$Date,"%y-%m-%d")
house=house %>% drop_na()
class(house$Date)
[1] "Date"
House=house %>%
select(Date, median_listing_price, median_square_feet)
head(House)
        Date median_listing_price median_square_feet
1 2022-08-01               435050               1890
2 2022-07-01               449024               1890
3 2022-06-01               450000               1887
4 2022-05-01               446950               1861
5 2022-04-01               425000               1821
6 2022-03-01               404950               1800

Make an xts object and index of times

# make an xts object
xts_House <- xts::xts(x= house %>% select(median_listing_price, median_square_feet),
                      order.by = house %>% pull(Date)) # x axis
class(xts_House)
[1] "xts" "zoo"
# index of the time
head(attr(xts_House,"index"))
[1] 1498867200 1501545600 1504224000 1506816000 1509494400 1512086400

Data visualization (make a Figure)

graph <- dygraph(xts_House, main = "Evolution of the median (listing price & square feet) from 2017 to 2020") %>%
dySeries("median_listing_price", label = "Median listing price") %>%
dySeries("median_square_feet", label = "Median square feet") %>%
dyRangeSelector() %>%
dyOptions(stackedGraph = TRUE)

Save figure as PDF

pdf("interaction_assignmnent.pdf", height=4, width=6)
print(graph)
dev.off()
png 
  2 

Display Figure in HTLM

graph