r - How to fix error in legend()? -
i not place text in "topright" of plot using legend()instead text getting on "topleft".please me out. in advance. , here code
library(ggplot2) library(reshape2) data_full <- read.table("household_power_consumption.txt",skip = 1,header = true, sep = ";") names(data_full) <- c("date","time","global_active_power","global_reactive_power","voltage","global_intensity","sub_metering_1","sub_metering_2","sub_metering_3") #subsetting required data data <- subset(data_full, data_full$date == "1/2/2007" | data_full$date == "2/2/2007") #transforming date , time variables objects of date , posixct resp datetime <- paste(as.date(data$date) ,data$time) data$datetime <- as.posixct(datetime) #using plot function plot(data$sub_metering_1,data$datetime,type = "n",ylab = "energy sub metering",xlab = "") lines(data$sub_metering_2,data$datetime, col = 'red') lines(data$sub_metering_3,data$datetime, col = 'blue') legend("topright",col = c("black","red","blue"),lty = 1,lwd = 2,legend=c("sub_metering_1","sub_metering_2","sub_metering_3")) #saving file dev.copy(png,file = "plot3.png", height = 480,width = 480) dev.off()
Comments
Post a Comment