R 获取范围太小,不允许出现最小n错误
我正在尝试用R绘制一些性能数据的折线图。我想绘制每个cpu和总数。我的txt文件中有一个名称列,我尝试将其设置为颜色,因为它们是因子。然而,我在prettyDate(x=x,n=n,min.n=min.n,sep=sep,…)中得到了这个错误R 获取范围太小,不允许出现最小n错误,r,ggplot2,R,Ggplot2,我正在尝试用R绘制一些性能数据的折线图。我想绘制每个cpu和总数。我的txt文件中有一个名称列,我尝试将其设置为颜色,因为它们是因子。然而,我在prettyDate(x=x,n=n,min.n=min.n,sep=sep,…)中得到了这个错误error: 最小值范围太小 这是我的密码 library(ggplot2) setwd("../../../PerfLogs") cpu<-read.delim("CPUUsage.txt", header=FALSE, sep="\t") name
error:
最小值范围太小
这是我的密码
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
中间一列是名称,右边一列是用法。我希望,因为它使用了一些因素,所以日期/时间是否完全相同并不重要。错误消息是因为您的x值是
datetime
,两个值之间的差值只有1秒(太小,无法显示数据)。您必须使用scale\u x\u datetime()
并将中断设置为“1秒”
,以显示数据
library(ggplot2)
library(scales)
ggplot(cpu, aes(Date, Usage, colour=Name)) +
geom_line(size=1) +
scale_x_datetime(breaks = date_breaks("1 sec"))
在这种情况下,最好使用dput(head())
而不是粘贴数据,因为您的时间列会使人们难以使用read.table(text=
等)。
library(ggplot2)
library(scales)
ggplot(cpu, aes(Date, Usage, colour=Name)) +
geom_line(size=1) +
scale_x_datetime(breaks = date_breaks("1 sec"))