Seq() 按分钟数生成数字 (R)
Seq() producing numbers off by minute amounts (R)
我正在尝试使用 seq()
来定义我在情节上的休息时间。下面的虚拟示例。
ggplot(data, aes(x=cat, y=dog) +
scale_y_continuous(breaks=seq(-0.3, 0.3, by=0.1))
出于某种原因,seq()
给我的输出数字按分钟计算。这种行为发生在我的绘图设备内外。如下所示,生成负数似乎是一个问题。它可以生产它们,但这就是问题所在。
seq(0.3, 0.9, by=0.1) # test with positives
seq(-0.3, 0.3, by = 0.1) # test with negatives
format(seq(-0.3, 0.3, by = 0.1), scientific = F) # show full number
我阅读了文档,但找不到任何关于底片的内容,所以我不确定如何修复它。我做错了什么或排除了什么吗?是否有解决方法或我应该使用的其他功能?
编辑
标记为重复但重复没有明确提供解决方案。这里有一些:
# i went with this solution as given in comments to keep it all contained within seq()
seq(-0.3, 0.3, length.out=7)
# from the answers
seq(-3, 3, by=1)/10
# didn't work for my case but should work as a general rule
round(x, digits=n) # x would be the seq(-0.3, 0.3, by = 0.1) and n=1 in my case)
对于解决方法,您可以尝试 seq(-3,3,1)/10
我正在尝试使用 seq()
来定义我在情节上的休息时间。下面的虚拟示例。
ggplot(data, aes(x=cat, y=dog) +
scale_y_continuous(breaks=seq(-0.3, 0.3, by=0.1))
出于某种原因,seq()
给我的输出数字按分钟计算。这种行为发生在我的绘图设备内外。如下所示,生成负数似乎是一个问题。它可以生产它们,但这就是问题所在。
seq(0.3, 0.9, by=0.1) # test with positives
seq(-0.3, 0.3, by = 0.1) # test with negatives
format(seq(-0.3, 0.3, by = 0.1), scientific = F) # show full number
我阅读了文档,但找不到任何关于底片的内容,所以我不确定如何修复它。我做错了什么或排除了什么吗?是否有解决方法或我应该使用的其他功能?
编辑 标记为重复但重复没有明确提供解决方案。这里有一些:
# i went with this solution as given in comments to keep it all contained within seq()
seq(-0.3, 0.3, length.out=7)
# from the answers
seq(-3, 3, by=1)/10
# didn't work for my case but should work as a general rule
round(x, digits=n) # x would be the seq(-0.3, 0.3, by = 0.1) and n=1 in my case)
对于解决方法,您可以尝试 seq(-3,3,1)/10