草庐IT

关于 r:Error ggplot (Error in seq.int(0, to0 – from, by) : ‘to’ must befinite)

codeneng 2023-03-28 原文

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",
            "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

而数据是:

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] 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

我遇到了以下错误:

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"))

有关关于 r:Error ggplot (Error in seq.int(0, to0 – from, by) : ‘to’ must befinite)的更多相关文章

  1. ruby - 将数组的内容转换为 int - 2

    我需要读入一个包含数字列表的文件。此代码读取文件并将其放入二维数组中。现在我需要获取数组中所有数字的平均值,但我需要将数组的内容更改为int。有什么想法可以将to_i方法放在哪里吗?ClassTerraindefinitializefile_name@input=IO.readlines(file_name)#readinfile@size=@input[0].to_i@land=[@size]x=1whilex 最佳答案 只需将数组映射为整数:@land边注如果你想得到一条线的平均值,你可以这样做:values=@input[x]

  2. ruby - 主要 :Object when running build from sublime 的未定义方法 `require_relative' - 2

    我已经从我的命令行中获得了一切,所以我可以运行rubymyfile并且它可以正常工作。但是当我尝试从sublime中运行它时,我得到了undefinedmethod`require_relative'formain:Object有人知道我的sublime设置中缺少什么吗?我正在使用OSX并安装了rvm。 最佳答案 或者,您可以只使用“require”,它应该可以正常工作。我认为“require_relative”仅适用于ruby​​1.9+ 关于ruby-主要:Objectwhenrun

  3. ruby-on-rails - rails : save file from URL and save it to Amazon S3 - 2

    从给定URL下载文件并立即将其上传到AmazonS3的更直接的方法是什么(+将有关文件的一些信息保存到数据库中,例如名称、大小等)?现在,我既不使用Paperclip,也不使用Carrierwave。谢谢 最佳答案 简单明了:require'open-uri'require's3'amazon=S3::Service.new(access_key_id:'KEY',secret_access_key:'KEY')bucket=amazon.buckets.find('image_storage')url='http://www.ex

  4. ruby - 续集在添加关联时访问many_to_many连接表 - 2

    我正在使用Sequel构建一个愿望list系统。我有一个wishlists和itemstable和一个items_wishlists连接表(该名称是续集选择的名称)。items_wishlists表还有一个用于facebookid的额外列(因此我可以存储opengraph操作),这是一个NOTNULL列。我还有Wishlist和Item具有续集many_to_many关联的模型已建立。Wishlist类也有:selectmany_to_many关联的选项设置为select:[:items.*,:items_wishlists__facebook_action_id].有没有一种方法可以

  5. ruby-on-rails - rails : How to make a form post to another controller action - 2

    我知道您通常应该在Rails中使用新建/创建和编辑/更新之间的链接,但我有一个情况需要其他东西。无论如何我可以实现同样的连接吗?我有一个模型表单,我希望它发布数据(类似于新View如何发布到创建操作)。这是我的表格prohibitedthisjobfrombeingsaved: 最佳答案 使用:url选项。=form_for@job,:url=>company_path,:html=>{:method=>:post/:put} 关于ruby-on-rails-rails:Howtomak

  6. ruby-on-rails - link_to 不显示任何 rails - 2

    我试图在索引页中创建一个超链接,但它没有显示,也没有给出任何错误。这是我的index.html.erb代码。ListingarticlesTitleTextssss我检查了我的路线,我认为它们也没有问题。PrefixVerbURIPatternController#Actionwelcome_indexGET/welcome/index(.:format)welcome#indexarticlesGET/articles(.:format)articles#indexPOST/articles(.:format)articles#createnew_articleGET/article

  7. ruby - 无法覆盖 irb 中的 to_s - 2

    我在pry中定义了一个函数:to_s,但我无法调用它。这个方法去哪里了,怎么调用?pry(main)>defto_spry(main)*'hello'pry(main)*endpry(main)>to_s=>"main"我的ruby版本是2.1.2看了一些答案和搜索后,我认为我得到了正确的答案:这个方法用在什么地方?在irb或pry中定义方法时,会转到Object.instance_methods[1]pry(main)>defto_s[1]pry(main)*'hello'[1]pry(main)*end=>:to_s[2]pry(main)>defhello[2]pry(main)

  8. ruby-on-rails - 错误 : Error installing pg: ERROR: Failed to build gem native extension - 2

    我克隆了一个rails仓库,我现在正尝试捆绑安装背景:OSXElCapitanruby2.2.3p173(2015-08-18修订版51636)[x86_64-darwin15]rails-v在您的Gemfile中列出的或native可用的任何gem源中找不到gem'pg(>=0)ruby​​'。运行bundleinstall以安装缺少的gem。bundleinstallFetchinggemmetadatafromhttps://rubygems.org/............Fetchingversionmetadatafromhttps://rubygems.org/...Fe

  9. ruby-on-rails - Rails 6 中的 protect_from_forgery? - 2

    protect_from_forgery默认Rails6应用程序不包含在我的应用程序Controller中,但是有嵌入式ruby​​在主应用程序布局中。这是否意味着protect_from_forgery方法已经被抽象并且在应用程序Controller中不再明确需要?我买了实用程序员的Rails6一书,我唯一能找到的是“csrf_meta_tags()方法设置了防止跨站点请求伪造攻击所需的所有幕后数据”。 最佳答案 对于rails5.2和更高版本,默认情况下在ActionController::Base上启用。查看此提交:https

  10. ruby-on-rails - Prawn PDF : I need to generate nested tables - 2

    我需要一个表,其中行实际上是2行表,一个嵌套表是..我怎样才能在Prawn中做到这一点?也许我需要延期..但哪一个? 最佳答案 现在支持子表:Prawn::Document.generate("subtable.pdf")do|pdf|subtable=pdf.make_table([["sub"],["table"]])pdf.table([[subtable,"original"]])end 关于ruby-on-rails-PrawnPDF:Ineedtogeneratenested

随机推荐