获取范围对于min.n错误来说太小 [英] Getting range is too small for min.n error
问题描述
我正在尝试使用R收集的一些性能数据的线图。我想绘制每个cpu和总数的图。我在我的txt文件中有一个名称列,我尝试将它设置为颜色,因为它们是因素。但是,我得到这个错误在prettyDate(x = x,n = n,min.n = min.n,sep = sep,...)中出错:
范围对于最小值来说太小。
I am trying to make a line graph of some performance data that I have collected using R. I want to graph each cpu and the total. I have a Names column in my txt file and I try set that to the color since they are factors. However I get this error Error in prettyDate(x = x, n = n, min.n = min.n, sep = sep, ...) :
range too small for min.n
Here is my code.
library(ggplot2)
setwd("../../../PerfLogs")
cpu<-read.delim("CPUUsage.txt", header=FALSE, sep="\t")
names(cpu)<-c("Date", "Name", "Usage")
dates<-as.character(cpu$Date)
dates<-strptime(cpu$Date, "%m/%d/%Y %I:%M:%S %p")
cpu$Date<-dates
graph<-ggplot(cpu, aes(cpu$Date, cpu$Usage, colour=cpu$Name)) + geom_line(size=1.0)
graph
下面是一些示例来自CPUUsage.txt的数据
Here is some sample data from CPUUsage.txt
2/13/2013 1:37:17 PM 0 0
2/13/2013 1:37:17 PM 1 18
2/13/2013 1:37:17 PM 2 6
2/13/2013 1:37:17 PM 3 18
2/13/2013 1:37:17 PM 4 6
2/13/2013 1:37:17 PM 5 18
2/13/2013 1:37:17 PM 6 6
2/13/2013 1:37:17 PM 7 6
2/13/2013 1:37:17 PM _Total 10
2/13/2013 1:37:18 PM 0 16
2/13/2013 1:37:18 PM 1 5
2/13/2013 1:37:18 PM 2 28
2/13/2013 1:37:18 PM 3 0
2/13/2013 1:37:18 PM 4 22
2/13/2013 1:37:18 PM 5 5
2/13/2013 1:37:18 PM 6 5
2/13/2013 1:37:18 PM 7 16
2/13/2013 1:37:18 PM _Total 12
中间栏是名称,右侧栏是用量。我希望自从它使用因素不重要,如果日期/时间是完全相同的
The middle column is Name and the right column is Usage. I was hoping since it used factors it wouldn't matter if the date / times were exactly the same
推荐答案
错误信息是因为你的x值是 datetime
,并且两个值之间的差值仅为1秒(太小而不能显示数据)。您必须使用 scale_x_datetime()
并将 breaks
设置为1秒$
The error message is due to fact that your x values are datetime
and difference between two values is just one second (too small to show data). You have to use scale_x_datetime()
and set breaks
to "1 sec"
to show your data.
library(ggplot2)
library(scales)
ggplot(cpu, aes(Date, Usage, colour=Name)) +
geom_line(size=1) +
scale_x_datetime(breaks = date_breaks("1 sec"))
这篇关于获取范围对于min.n错误来说太小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!