is it possible to scale Hour and Minute as factors in y-axis?

I have a data frame like this:

dput(head(t,30))

structure(list(DATE = structure(c(15744, 15744, 15744, 15744, 
15744, 15744, 15744, 15744, 15744, 15744, 15744, 15744, 15744, 
15744, 15744, 15744, 15744, 15744, 15744, 15744, 15744, 15744, 
15744, 15744, 15744, 15744, 15744, 15744, 15744, 15744), class = "Date"), 
    TIME1 = c("00:14", "00:29", "00:44", "00:59", "01:14", "01:29", 
    "01:44", "01:59", "02:14", "02:29", "02:44", "02:59", "03:14", 
    "03:29", "03:44", "03:59", "04:14", "04:29", "04:44", "04:59", 
    "05:14", "05:29", "05:44", "05:59", "06:14", "06:29", "06:44", 
    "06:59", "07:14", "07:29"), CPU = c(27.7058823529412, 28.1, 
    25.5444444444444, 24.4333333333333, 25.3222222222222, 22.3666666666667, 
    20.8555555555556, 19.5777777777778, 20.8555555555556, 20.0333333333333, 
    19.1888888888889, 18.5444444444444, 19.3333333333333, 19.0222222222222, 
    17.3111111111111, 17.2777777777778, 17.2777777777778, 17.1555555555556, 
    17.2333333333333, 17.3777777777778, 17.5444444444444, 18.2222222222222, 
    17.7444444444444, 18.6333333333333, 21.6333333333333, 23.9, 
    27.9666666666667, 28.5222222222222, 32.1777777777778, 33.0111111111111
    )), .Names = c("DATE", "TIME1", "CPU"), row.names = c(NA, 
30L), class = "data.frame")

I am trying to create a ggplot that will have DATE on x-axis and TIME1 on the y-axis. Currently, If I try to plot it, I see all the values of TIME1 on the y-axis and making it very difficult to read the graph.

Is there a way to scale TIME1 on y-axis?

as hightlighted on the blog post (http://blog.ggplot2.org/post/29433173749/defining-a-new-transformation-for-ggplot2-scales-part), I have done the following:

t$TIME<-times(t$TIME1)

times_trans <- function() {
    fmt <- function(x) {
        format(x, simplify = !any(diff(x) < 1/(24*60)))
    }
    trans_new("chrontimes",
              transform = as.numeric,
              inverse = times,
              breaks = pretty_breaks(),
              format = fmt,
              domain=c(0,1))
}


timesreverse_trans <- function() {
    trans <- function(x) {-as.numeric(x)}
    inv <- function(x) {times(-x)}
    fmt <- function(x) {format(x, simplify = !any(diff(x) < 1/(24*60)))}
    trans_new("chrontimes-reverse",
              transform = trans,
              inverse = inv,
              breaks = pretty_breaks(),
              format = fmt,
              domain=c(0,1))
}


scale_y_times <- function(..., trans=NULL) {
    scale_y_continuous(trans=timesreverse_trans(), ...)
}

THEN

When I do this:

ggplot(t,aes(DATE, TIME1, group=SERVER, fill=CPU)) + geom_tile() + facet_wrap(~SERVER) +scale_y_times()

I get values from 00:00, 00:25, 00:50, 00:75, 1 values on the y-axis. Any ideas what I might be missing here?

when I compare Brian Diggs post dat data frame with mine, they are identical:

str(t)
'data.frame':   55076 obs. of  4 variables:
 $ TIME  :Class 'times'  atomic [1:55076] 0.0101 0.0205 0.0309 0.0413 0.0517 ...
  .. ..- attr(*, "format")= chr "h:m:s"
 $ CPU   : num  27.7 28.1 25.5 24.4 25.3 ...
 $ SERVER: chr  "cigp04a4a002" "cigp04a4a002" "cigp04a4a002" "cigp04a4a002" ...
 $ DATE  : Date, format: "2013-02-08" "2013-02-08" "2013-02-08" "2013-02-08" ...

\n

str(dat)
'data.frame':   11 obs. of  2 variables:
 $ time :Class 'times'  atomic [1:11] 0.776 0.702 0.629 0.556 0.482 ...
  .. ..- attr(*, "format")= chr "h:m:s"
 $ value: int  7 6 9 11 10 1 4 2 3 5 ...

when I do graph his dat data frame I do get the Hour and Minute on the y-axis. when I try to graph my t data frame, y-axis is from 0.00, 0.25, 0.50, 0.75 and 1.0.

Answers


The values in TIME1 are probably not stored as actual times. When I read your data and do this:

sapply(t, class)

It reports that TIME1 is stored as character. You need to change that to a time object e.g.:

t$TIME1 <- as.POSIXlt(t$TIME1, format='%H:%M')

The plots works for me then. At least I think that's what you're asking for.

P.S. I would avoid using t as a variable name, that's a base function.


Need Your Help

Trouble with nvcc when building Opencv 2.4.3 with cuda5 support on windows 7

c++ visual-studio-2008 opencv cuda

I have trouble to build OpenCV 2.4.3 library with support of CUDA (version 5) using cmake.

How to safely use reply and !? on a Scala Actor

scala actor

Depending on a reply from a Scala Actor seems incredibly error-prone to me. Is this truly the idiomatic Scala way to have conversations between actors? Is there an alternative, or a safer use of re...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.