Reputation: 21
I'm generating a simple line plot in R, however it adds another unwanted straight horizontal line to my plot that I don't want. And it happens in all of my line plots. I have tried google, however it only gives me instructions on how to add an extra line and not why this is happening. I am using RStudio 0.98.1028 on Mac OS X Yosemite.
plot(data2$interval,data2$steps,main="Plot of Average Activity",
xlab = "Interval", type="l", ylab="Average steps taken")
Upvotes: 2
Views: 985
Reputation: 156
I guess the problem is with your data. You might have rows at the end of the data frame that "return" to the origin. Here you have a reproducible example:
data2 <- data.frame(interval = 1:200, steps = rnorm(200, 50, 20))
data2[1,2] <- 0
data2[200,2] <- 0
data2[201, ] <- c(0, 0)
plot(data2$interval,data2$steps,main="Plot of Average Activity",
xlab = "Interval", type="l", ylab="Average steps taken")
please vote if the answer is fine with you :)
Upvotes: 4