Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting range is too small for min.n error

Tags:

r

ggplot2

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

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

like image 257
tympaniplayer Avatar asked Jan 29 '26 02:01

tympaniplayer


1 Answers

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

enter image description here

like image 169
Didzis Elferts Avatar answered Jan 31 '26 22:01

Didzis Elferts



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!