Error ggplot (Error in seq.int(0, to0 – from, by) : ‘to’ must be finite)
为了用 ggplot2 绘制数据,我遇到了以下错误。
可用的命令、数据和错误类型如下:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
require(ggplot2)
require(reshape2) df <- data.frame(HMn25_30$avg,dt_hmn$dt) df[3] = c( “Normal”, “Normal”, |
而数据是:
1
2 3 4 5 6 7 8 9 10 |
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
|
Error in seq.int(0, to0 – from, by) : ‘to’ must be finite
|
- 其中哪一行给出了错误信息?你能把它缩短一点吗,因为现在有太多不必要的行(例如使用 theme()),你也可以使用 dput(df.m) 来提供你的数据。
- @DidzisElferts,错误发生在”p”之后的最后一行。
- 您的代码中存在许多问题,但首先可能在您使用 striptime() 的位置 – format= 错误,因为您的初始日期格式 =”%m/%d/%Y %H:%M”。也尽量不要对每一行使用 p<-p … ,这样你就不能轻易地检测到问题。在每次更改后绘制你的情节,看看它是否有效
您的代码中的第一个问题是 striptime() 中的 format= 有错误的参数格式 – 它与实际的日期格式不对应。它应该是 format =”%m/%d/%Y %H:%M”
1
|
df.m$dt_hmn.dt <- strptime(as.character(df.m$dt_hmn.dt), format =”%m/%d/%Y %H:%M”)
|
ggplot() 代码的下一步 – 如果您为 geom_point() 中的所有点设置 color=”blue”,则不需要使用 scale_color_manual(),也可以在 aes() 中使用 color=variable。对于 scale_shape_manual() 没有形状 27,将其更改为 17.
如果您使用 theme_bw(),那么其他 theme() 调用应放在此行之后,以确保 theme_bw() 不会覆盖您的参数。
1
2 3 4 5 6 7 8 9 10 |
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”)) |
来源:https://www.codenong.com/15897087/