2/13/2020

Introduction

Create a web page presentation using R Markdown that features a plot created with Plotly. Host your webpage on either GitHub Pages, RPubs, or NeoCities. Your webpage must contain the date that you created the document, and it must contain a plot created with Plotly. We would love to see you show off your creativity!

Getting the data

library(dplyr)
  dataPath <- paste(getwd(), "household_power_consumption.txt", sep = "/")

 data <- read.table(dataPath, sep = ";", skip = 1,col.names = c("Date", "Time", "Global_active_power", "Global_reactive_power", "Voltage", "Global_intensity", "Sub_metering_1", "Sub_metering_2", "Sub_metering_3"))

Initialization

dates <- data[1]

times <- data[2]

Global_active_power <- data[3]

Global_active_power <- as.vector(t(Global_active_power))
Global_active_power <- suppressWarnings(as.numeric(Global_active_power))
rem_na <- !is.na(Global_active_power)
dates <- as.vector(t(dates))
times <- as.vector(t(times))
x <- paste(dates, times)
  
date_time <- strptime(x, "%d/%m/%Y %H:%M:%S")

con <- date_time > strptime("01/02/2007 00:00:00", "%d/%m/%Y %H:%M:%S") & date_time < strptime("03/02/2007 00:00:00", "%d/%m/%Y %H:%M:%S")
d1 <- date_time[con]

Plotting

plot_ly( x = Global_active_power[con],
         mode = "lines+markers",
         marker = list( size = 14, color = "#52006d" ),
         showlegend = FALSE,
         hoverinfo = "text",
         text = paste0( d1,
                        "Incidents: ",
                        Global_active_power[con]) ) %>%
  layout( showlegend = FALSE,
          title = "Incidents by month",
          xaxis = list( title = "",
                        ticks = "inside",
                        tickangle = 14 ),
          yaxis = list( title = "Global Active Power (killowatts)",
                        ticks = "inside",
                        gridwidth = 3,
                        gridcolor = "lightgray" ) )

Plot

Thank You!