rethomics / ggetho

Visualise high throughput behavioural data in R, based on ggplot2
http://rethomics.github.io
8 stars 3 forks source link

Changing color scale for stat_tile_etho/adding geoms #37

Open CitrusFlavorrr opened 4 years ago

CitrusFlavorrr commented 4 years ago

Hello Quentin! I am using ggetho to plot activity patterns of raccoons over the course of the year (you previously helped me format my data to work with ggetho, thank you again!). I've continued working with this, and I want to change the color scale from the default blue/black to a blue/red. Is there some argument to do this within stat_tile_etho?

Additionally, I have been having trouble adding geoms to this figure because the weeks are stored as ids, not continuous variables, in the behavr tables. For example, I want to plot a line showing when the sunrise and sunset is over the course of the year. I have this average value for each week, but haven't been able to add it to the ggetho plot with a geom_vline. Is there some way to do this within ggetho or behavr tables without ggplot2?

Thanks! Jacob

qgeissmann commented 4 years ago

hey @CitrusFlavorrr ,

Sure, so, something like that for instance: image

For the colour, just use one of the scale_fill_* functions, such as scale_fill_gradient2 in ggplot, see below. For line, I can use geom_vline directly, but if you want to use something fancier, you can always use inherit.aes = FALSE, and define a layer with its own data and aes, see my geom_line

library(ggetho)
metadata <- data.frame(id = sprintf("toy_experiment | %02d", 1:20),
                       age = c(1, 5, 10, 20),
                       condition = c("A", "B"))
dt <- toy_activity_data(metadata, 3)

pl <-  ggetho(dt, aes(z = asleep), multiplot = 2, multiplot_period = hours(24)) + 
  stat_tile_etho() + 
  scale_fill_gradient2() + 
  geom_vline(xintercept = hours(12))+
  geom_line(aes(x,y),data.frame(x = c(0,hours(48)), y = c(4, 0)), inherit.aes = FALSE)

pl