Reputation: 421
For plotting the data with ggplot2
, I have faced with following error.
The commands, data and error types are available as following:
require(ggplot2)
require(reshape2)
df <- data.frame(HMn25_30$avg,dt_hmn$dt)
df[3] = c( "Normal", "Normal",
"Normal",
"Normal",
"Normal",
"Normal",
"Normal",
"Normal",
"Normal",
"Normal",
"Outlier",
"Outlier",
"Outlier",
"Outlier",
"Outlier",
"Outlier",
"Normal",
"Outlier",
"Outlier",
"Normal",
"Normal",
"Outlier",
"Outlier",
"Normal",
"Normal"
)
names(df)[1] <- 'Node 25'
names(df)[3] <-'Results'
df.m <- melt(df, names(df)[2:3], names(df)[1])
df.m$Results <- factor(df.m$Results)
df.m$dt_hmn.dt <- strptime(as.character(df.m$dt_hmn.dt), format = "%Y-%m-%d %H:%M")
p <- ggplot(df.m, aes(x = dt_hmn.dt, y = value, group = variable, color = variable))
p <- p + scale_shape_manual(values=c(27,20))
p <- p + geom_point(aes(shape = Results), cex=13, color= "blue")
p <- p + theme(axis.text.x = element_text(angle = 90, hjust = 1, size=13,color="darkred"))
p <- p + scale_color_manual(values=c("Red"))
p <- p + ylim(-1,8)
p <- p + theme_bw()
p <- p + xlab('Date and Time')
p <- p + ylab('Temprature')
p <- p + ggtitle("Temporal Outliers of Node 25 ") + theme(plot.title = element_text(lineheight=3, face="bold", color="black", size=29))
p
And the data are:
HMn25_30$avg
[1] 0.280 0.208 -0.264 -0.480 -0.708 -0.714 -0.498 -0.216 0.126 0.574 1.042 1.086 1.820
[14] 4.570 3.808 7.400 5.572 5.402 6.288 4.966 5.180 2.380 4.710 5.366 4.766
dt_hmn$dt
[1] 9/29/2007 23:00 9/30/2007 0:00 9/30/2007 1:00 9/30/2007 2:00 9/30/2007 3:00
[6] 9/30/2007 4:00 9/30/2007 5:00 9/30/2007 6:00 9/30/2007 7:00 9/30/2007 8:00
[11] 9/30/2007 9:00 9/30/2007 10:00 9/30/2007 11:00 9/30/2007 12:00 9/30/2007 13:00
[16] 9/30/2007 14:00 9/30/2007 15:00 9/30/2007 16:00 9/30/2007 17:00 9/30/2007 18:00
[21] 9/30/2007 19:00 9/30/2007 20:00 9/30/2007 21:00 9/30/2007 22:00 9/30/2007 23:00
I have faced the following error:
Error in seq.int(0, to0 - from, by) : 'to' must be finite
Upvotes: 5
Views: 32439
Reputation: 98549
First problem in your code is that format=
in striptime()
had the wrong argument format - it didn't correspond to actual date format. It should be format = "%m/%d/%Y %H:%M"
df.m$dt_hmn.dt <- strptime(as.character(df.m$dt_hmn.dt), format = "%m/%d/%Y %H:%M")
Next for the ggplot()
code - if you set color="blue"
for all points in geom_point()
you don't need to use scale_color_manual()
and also use color=variable
inside aes()
. For scale_shape_manual()
there is no shape 27
, changed it to 17
.
If you use theme_bw()
then other theme()
calls should be placed after this line to be sure that theme_bw()
won't override your parameters.
ggplot(df.m, aes(x = dt_hmn.dt, y = value, group = variable)) +
geom_point(aes(shape = Results), cex=13, color= "blue")+
scale_shape_manual(values=c(17,20))+
ylim(-1,8)+
theme_bw()+
xlab('Date and Time') +
ylab('Temprature')+
ggtitle("Temporal Outliers of Node 25 ") +
theme(plot.title = element_text(lineheight=3, face="bold", color="black", size=29))+
theme(axis.text.x = element_text(angle = 90, hjust = 1, size=13,color="darkred"))
Upvotes: 4