colour scale for POSIXlt times in 0.9.2

35 views
Skip to first unread message

Ronan Le Hy

unread,
Nov 6, 2012, 11:14:45 AM11/6/12
to ggp...@googlegroups.com
Hello,

I just upgraded from ggplot2 0.9.1 to 0.9.2.1. The way POSIXlt times are mapped to colours has changed, and I don't know how to get back to the old behaviour.

0.9.1:
 The colour scale is a continuous gradient (dark to light blue).

0.9.2/0.9.2.1:
 The colour scale is discretized.

Is there a way to get back the gradient scale in 0.9.2.1? (I did try to search the changelog and the mailing list, to no avail. Pointers to previous discussions would of course be appreciated.)

Here is my code:

library(reshape)
library(ggplot2)

dat <- mutate(data.frame(x=seq(0,10,0.1)),
              y = sin(x),
              t = as.POSIXlt(sprintf("2012-07-18 20:%d:%f", as.integer(x), x)))

summary(dat)

ggplot.version <- sessionInfo("ggplot2")$otherPkgs$ggplot2$Version
cat("this is ggplot2 version", ggplot.version, "\n")

p <- ggplot(dat) + geom_point(aes(x=x, y=y, color=t))
ggsave(sprintf("time-color-%s.png", ggplot.version))

-- 
Ronan
ggplot-time-color.R

Ronan Le Hy

unread,
Nov 6, 2012, 11:21:50 AM11/6/12
to ggplot2

2012/11/6 Ronan Le Hy <ronan...@gmail.com>
I just upgraded from ggplot2 0.9.1 to 0.9.2.1. The way POSIXlt times are mapped to colours has changed, and I don't know how to get back to the old behaviour.
[...]
Here is my code:

library(reshape)
library(ggplot2)

dat <- mutate(data.frame(x=seq(0,10,0.1)),
              y = sin(x),
              t = as.POSIXlt(sprintf("2012-07-18 20:%d:%f", as.integer(x), x)))

summary(dat)

ggplot.version <- sessionInfo("ggplot2")$otherPkgs$ggplot2$Version
cat("this is ggplot2 version", ggplot.version, "\n")

p <- ggplot(dat) + geom_point(aes(x=x, y=y, color=t))
ggsave(sprintf("time-color-%s.png", ggplot.version))

Sorry, these two last lines should be:

Ista Zahn

unread,
Nov 6, 2012, 11:36:42 AM11/6/12
to Ronan Le Hy, ggp...@googlegroups.com
Hi,

Not sure if this is the recommended way, but

library(lubridate)
ggplot(dat) + geom_point(aes(x=x, y=y, color=second(t)))

seems to work.

Best,
Ista
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
> https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2

Ronan Le Hy

unread,
Nov 7, 2012, 3:10:45 AM11/7/12
to Ista Zahn, ggp...@googlegroups.com
2012/11/6 Ista Zahn <ista...@gmail.com>
> Not sure if this is the recommended way, but
> library(lubridate)
> ggplot(dat) + geom_point(aes(x=x, y=y, color=second(t)))
> seems to work.

Thanks.

It does fix the color scale, but then the legend is unusable (it says
"second(t)" instead of "t", and the values are not proper times).

--
Ronan

Hadley Wickham

unread,
Nov 7, 2012, 8:32:23 AM11/7/12
to Ronan Le Hy, ggp...@googlegroups.com
> dat <- mutate(data.frame(x=seq(0,10,0.1)),
> y = sin(x),
> t = as.POSIXlt(sprintf("2012-07-18 20:%d:%f", as.integer(x),
> x)))

I wouldn't recommend putting POSIXlt in a dataframe - use POSIXct.

Hadley

--
RStudio / Rice University
http://had.co.nz/

Winston Chang

unread,
Nov 7, 2012, 3:16:38 PM11/7/12
to Ronan Le Hy, ggplot2
Hm, that looks like a bug. I've filed it here:

-Winston



-- 
Ronan

--
Reply all
Reply to author
Forward
0 new messages