r - change labels in legend for ggplot2 -


i have time series data , want plot x vs y , color (gradient) datetime converting datetime numeric, problem takes numeric value in legend well.

date         x        y 2012-01-01 14:25:00 461.2339 15.83793 2012-01-01 14:30:00 459.8557 15.80326  

here code

ggplot(test1_data,aes(x , y ,colour = as.numeric(date))) +   geom_point() +   scale_colour_gradientn(colours=rev(rainbow(6))) 

is there way edit legends show actual datetime?

you need use breaks , labels. here's example. you'll need change format suit actual data.

library("ggplot2") test1_data <- read.csv(text = "date,x,y                2012-01-01 14:25:00,461.2339,15.83793                2012-01-01 14:30:00,459.8557,15.80326",                header = true,                colclasses = c("posixct", rep("numeric", 2))) date_breaks <- diff(range(test1_data$date)) * 0:4 / 4 +   min(test1_data$date) date_labels <- format(date_breaks, "%h:%m:%s") ggplot(test1_data,aes(x , y ,colour = as.numeric(date))) +     geom_point() +     scale_colour_gradientn(colours=rev(rainbow(6)),                            breaks = as.numeric(date_breaks),                            labels = date_labels) 

Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -