Code Monkey home page Code Monkey logo

exdata_plotting1's Introduction

Author Date
Akhila G P
2020-06-25

Introduction

  • Description: Measurements of electric power consumption in one household with a one-minute sampling rate over a period of almost 4 years. Different electrical quantities and some sub-metering values are available.

The "Individual household electric power consumption Data Set" is used. The dataset can be downloaded from Electric power consumption [20Mb]

Dataset description

  1. Date: Date in format dd/mm/yyyy
  2. Time: time in format hh:mm:ss
  3. Global_active_power: household global minute-averaged active power (in kilowatt)
  4. Global_reactive_power: household global minute-averaged reactive power (in kilowatt)
  5. Voltage: minute-averaged voltage (in volt)
  6. Global_intensity: household global minute-averaged current intensity (in ampere)
  7. Sub_metering_1: energy sub-metering No. 1 (in watt-hour of active energy). It corresponds to the kitchen, containing mainly a dishwasher, an oven and a microwave (hot plates are not electric but gas powered).
  8. Sub_metering_2: energy sub-metering No. 2 (in watt-hour of active energy). It corresponds to the laundry room, containing a washing-machine, a tumble-drier, a refrigerator and a light.
  9. Sub_metering_3: energy sub-metering No. 3 (in watt-hour of active energy). It corresponds to an electric water-heater and an air-conditioner.
  10. DateTime: A column created for the purpose of plotting graphs; combines Date and Time column (format yyyy-mm-dd hh:mm:ss IST)

Loading the data

Data from the dates 2007-02-01 and 2007-02-02 only are used.

  • Using fread() from data.table package is faster compared to other read methods.

  • as.Date() and as.POSIXct() are used to appropriately format the Date and DateTime columns respectively

Making Plots

The four plots are constructed using the base plotting system.

  • The plots are stored in PNG files with width of 480 pixels and height of 480 pixels.

  • The plots' source code is stored in the same name as the plot. eg: plot1.R generates the plot1.png

The construced plots are as below and to reproduce the plots execute the corresponding R script

Plot 1

#plot1.R
with(f2, hist(Global_active_power, col = "red", xlab = "Global Active Power (kilowatts)",
			main = "Global Active Power"))

plot1.png

Plot 2

#plot2.R
with(f2, plot(DateTime, Global_active_power, type='l', 
	ylab = "Global Active Power (kilowatts)", xlab = ""))

plot2.png

Plot 3

#plot3.R
with(f2, {
    plot(DateTime, Sub_metering_1, type = 'l', ylab = "Energy sub metering", xlab = "")
    points(DateTime, Sub_metering_2, type='l', col="red")
    points(DateTime, Sub_metering_3, type='l', col="blue")
})

plot3.png

Plot 4

#plot4.R
par(mfrow=c(2,2))
with(f2,{
    #plot 1
    plot(DateTime, Global_active_power, type='l', ylab = "Global Active Power", xlab = "")
    
    #plot2
    plot(DateTime, Voltage, type = 'l')
    
    #plot3
    {
    plot(DateTime, Sub_metering_1, type = 'l', ylab = "Energy sub metering", xlab = "")
    points(DateTime, Sub_metering_2, type='l', col="red")
    points(DateTime, Sub_metering_3, type='l', col="blue")
    #setting the legend
    legend("topright", col = c("black", "red", "blue"), 
	c("Sub_metering_1", "Sub_metering_2","Sub_metering_3"), lty = "solid", bty="n")
    }
    
    #plot4
    plot(DateTime, Global_reactive_power, type = 'l')
})

plot4.png

exdata_plotting1's People

Contributors

akhilagp avatar rdpeng avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.