Git Product home page Git Product logo

ggetho's Introduction

ggetho's People

Contributors

qgeissmann avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ggetho's Issues

Movement Classification and Visualization

Does anyone have any guidance as to how I can go about classifying and visualizing fly movements using RStudio as either 'walking', 'micromovement' or 'immobile' as shown in the original ethoscope publication. I'd like to replicate the box plot and frequency plot similar to this figure:
image

Thank you!
@qgeissmann

time-wrap doesn't match expected length

Hi, I recently started using ggetho with some mouse activity data and I noticed that the data does not extend as far as predicted when using time-wrap. For an example, see the documentation:
image
time-wrap is set to 24 hours, but the graph and annotations only span ~23.5 hrs. Why is this?

Choosing specifics gentoypes in a plot

Hello, I am plotting sleep for three genotypes A,B and C using ggetho with the following code

ggetho(dt_curated, aes(y=asleep, colour=genotype)) + stat_pop_etho() + stat_ld_annotations()

This give me a sleep plot with all three genotypes. Is there a way to chose which genotypes to plot (ex. A and C)

Time warp 24 hours, sleep curves don't go all the way until the end of day

Hello, i am using time warp (24 hours) to average sleep behavior over multiple days in a single day (24 hours). However the sleep curve and the LD bar annotation do not reach the end of day, a period at the end of the day is missing as I see.

ggetho(dt_curated, aes(y=asleep, colour=genotype), time_wrap = hours(24)) + stat_pop_etho() + stat_ld_annotations() + facet_grid(genotype ~ .) + scale_y_continuous(name= "Fraction of time sleeping",labels = scales::percent)

Rplot

Bar plot functionality for ggetho

I would like a single value as an average activity over a time period for each individual. Somewhat like the graph I have attached but with Id's for each individual. I think this would be possible if I were able to melt the data like with library(reshape). Is there any way that I can do this with rethomics? The workflow would be: subset ->melt -> plot.
averageplot

error when trying to wrap data along a circadian day

Hello,
Thanks for making the ggetho package. I am having some trouble wrapping my DAM2 data along a circadian day.
screen shot 2017-10-17 at 3 00 20 pm
I do not, however, get this problem when I set y=asleep or y=moving with the toy data. Is there a way within the rethomics framework to turn my 'activity' data into something like 'moving' or 'asleep'?
Thanks

Issues with next version of ggplot2

Hi

We preparing the next release of ggplot2 and our reverse dependency checks show that your package is failing with the new version. Looking into it we see that your package somehow includes references to ggplot2 code from when it was build, which causes the check to emit the "Import not declared from..." error. Please see https://www.tidyverse.org/blog/2022/09/playing-on-the-same-team-as-your-dependecy/ for some more info about why this can cause issues.

You can install the release candidate of ggplot2 using devtools::install_github('tidyverse/[email protected]') to test this out.

We plan to submit ggplot2 by the end of October and hope you can have a fix ready before then

Kind regards
Thomas

ggetho() multiplot data differs in adjacent rows

Hello,
I'm experiencing some issues with the visualization of data using ggetho() function and the multiplot = 2 argument.

In particular, I found out that data are not consistent between rows, while instead the second half of a row should be repeated in the first half of the following row. (see image for clarification).

IMG_0937

Apparently this is more evident in those rows where the tiles are small, but when superimposing the two halves of the graph you can see that there is a slight difference in the height.

The snippet of code I used to generate the plot is

ggetho(sum, aes(x = t, z=counts_min),
       summary_time_window = 300,
       multiplot = 2,
       ) +
  theme_excel()+
  stat_ld_annotations(height = 1, alpha = 0.03, outline = NA, phase = 43200)+
  stat_bar_tile_etho()+
  facet_grid(Cabinet~gene)+
  ylab("")+
  ggtitle("Double plotted actogram", subtitle = "averaged by cabinet vs genotype, time window per each bin is 5'")

being the dataset 'sum' a timeserie table in long format, with a column for 'id' of different individues, 't' as progressing time
t <- seq(from = 0, to = 1295940, by = 60)
counts_ min is the column used for z axis and it has values ranging from 0 to 70
column named Cabinet and gene are factors that can assume only two different values each.

anybody has experienced the same issue/ knows how to solve this?

time_wrap when some individuals have NA values

I have a dataset of 12 individuals over 4 days. For one of the individuals, I had to remove the first ≈1 day of data - I replaced the activity values in this time range with NAs.

When I do a wrapped plot and facet by individual, the plot for the individual with the NA values is almost entirely empty. It seems that the mean function built into time_wrap will not handle NAs.

Is there a way to provide an argument to ggetho() so that the averaging performed by time_wrap will ignore NA values?

Thanks!

time offset and ld annotations fails on polar coordinates when time offset is not 0

library(behavr)
# We start by making a to dataset with 20 animals
metadata <- data.frame(id = sprintf("toy_experiment | %02d", 1:20),
                       condition = c("A", "B"))
dt <- toy_activity_data(metadata, 3)
# We build a plot object
pl <-  ggetho(dt, aes(y = asleep), time_offset = 1000, time_wrap = behavr::hours(24)) + stat_pop_etho() +coord_polar() +
stat_ld_annotations(height=.5,
                    alpha=.3,
                    ypos=0.015,
                    x_limits = c(0, 86400),
                    outline = NA, ld_colours = c('blue', 'red'))
pl
Warning messages:
1: In munched_lines$id + rep(c(0, max(ids, na.rm = TRUE)), each = length(ids)) :
  longer object length is not a multiple of shorter object length
2: Removed 1 rows containing missing values (geom_ld). 

image

Double plot controls on actogram

I can't seem to find a way to plot a control alongside my mutants unless I do them all on top of one another (which gets way too messy) or I have to make metadata files for each pair separately (which seems like a lot of work).

My dataset has 12 (and growing) phenotypic genotypes and controls. What I would like to do (for example) is plot the activity over time for the control and one of the mutant genotypes on the same plot for two plots total on the same axis. It should then go through and do this for all of the different genotypes.

I have tried:

  1. graphing both separately and adding them together (was hoping to make some kind of loop)
  2. extracting the two genotypes from the curated dataset, combining them back together, and then graphing from there (the datasets did not combine properly for some reason)
  3. duplicating the control data in the metadata file to make matching duplicates for every other genotype, labeling them as the same genotype, and then adding another column in the metadata to differentiate between 'control' and 'experimental' (resulted in errors loading the metadata file)
  4. A plethora of other things using facet_wrap and the like

Any suggestions would be appreciated!

autoscales break LD annotion

since scale transformation happens before stats.
To fix that, we should use "gosht" transformations where only the break label is changed, not the underlying values.

plot periodograms

so far, if we want to plot periodograms generated by zeitgebr:

library(ggetho)
library(zeitgebr)

metadata <- data.table(id=sprintf("toy_experiment|%02d" , 1:40), region_id=1:40,
                   condition=c("A","B"),
                   sex=c("M","M", "F", "F"))
dt <- toy_activity_data(metadata, seed=107)

dt[, t := ifelse(xmv(condition) == "A", t, t * 1.01)]
per_dt <- periodogram(moving, dt, FUN = chi_sq_periodogram)

ggplot(rejoin(per_dt), aes(period, power, colour=condition)) + 
        geom_line(mapping = aes(group = id), alpha=.1) + 
        scale_x_hours() + stat_summary(geom="smooth", fun.data =  mean_se)

image

this involes a manual rejoin, and an understanding of aes inheritance. I would rather have a ggperiodo() function that preprocesses the data like ggetho...

Changing color scale for stat_tile_etho/adding geoms

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

tile / bar plot hybrid

I am working on developing a tile plot for visualisation that, instead of plotting a colour intensity, builds a rectangle (i.e. bar). The height of the rectangle should be proportional to the value.

Artefact in chi sqr periodogram?

There are "drops" in the periodogram.
Their position seems to depend on the amount of data inputted, so probably a "wrapping" issue.
what do you think @pepelisu ?

library(zeitgebr)
library(ggetho)
data(dams_sample)
summary(dams_sample)
per <- periodogram(activity, dams_sample)
ggetho::ggperio(per, aes(y = power - signif_threshold, colour=period_group)) + stat_pop_etho()
per <- periodogram(activity, dams_sample[t < days(8)])
ggetho::ggperio(per, aes(y = power - signif_threshold, colour=period_group)) + stat_pop_etho()
per <- periodogram(activity, dams_sample[t < days(6)])
ggetho::ggperio(per, aes(y = power - signif_threshold, colour=period_group)) + stat_pop_etho()

image
image
image

plotting problems after updating ggplot

I have this problem with my on data, but I reproduced it with the damr tutorial data from the webpage. This is my script:

DATA_DIR <- "C:/Users/ebeckwit/Desktop/damr_tutorial"

list.files(DATA_DIR, pattern= "*.txt|*.csv")

setwd(DATA_DIR)

library(damr)
metadata <- fread("metadata.csv")
metadata

metadata <- link_dam_metadata(metadata, result_dir = DATA_DIR)
metadata

dt <- load_dam(metadata)
summary(dt)

library(ggetho)

ggetho(dt[xmv(replicate) == 1 ], aes(z=activity)) +
  stat_tile_etho() +
  stat_ld_annotations()

and I get this error message:

Error in ggetho(dt[xmv(replicate) == 1], aes(z = activity)) : 
  Either `y` or `z` should be provided as variable of interest

Specifying axis limits via scale_y_continuous CHANGES DATA ?

I'm using stat_pop_etho() and would like to specify y-axis limits so that I make lots of different plots that all have the same y-axis range.

However, using scale_y_continuous() to specify limits=c(XXX,XXX) ends up changing the values of the data represented, which is alarming.

See the two plots attached here. Plot1 is how it comes out without specifying y-axis limits; Plot2 is how it comes out if I include
scale_y_continuous(limits=c(500,3500))

What am I doing wrong? Thanks for your help!

  • Brooks

Plot1_noYaxisLimitsSpecified.pdf
Plot1_WITH_YaxisLimitsSpecified.pdf

error bars are never drawn by stat_pop_etho

e.g.

  library(behavr)
     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)
     # We build a plot object
     pl <-  ggetho(dt, aes(y = asleep))
     # A standard plot of the whole population:
     pl + stat_pop_etho()

Polar coordinate plots - grey centre circle and activity lines not continuous

Hello!

I'm having some difficulties with using Rethomics to produce polar coordinate plots. The centre of the plot has a grey circle that coincides with what should be the light phase (the right side of the plot, from 0-12h). Also, the activity appears to not be continuous in that it does not fully close at 0/24 h. I've posted my code below, as well as the polar coordinate plot and actogram I produced using this code. Data and metadata are also attached in a zip (archive.zip). Any advice or help is much appreciated!

Archive.zip

rm(list=ls())

library(behavr)
library(ggetho)
library(zeitgebr)
library(lubridate)
library(ggplot2)
library(RColorBrewer)
library(tidyverse)

#load data
metadata <- fread("Your/path/to/data.csv")
df <- fread("Your/path/to/data.csv")

df <- na.omit(df)

df$time <- as.POSIXct(df$time, format="%d/%m/%Y %H:%M") 
#create a fake time that's one day earlier at ZT0
df$start.time<-paste0(date(min(df$time)-86400)," 18:00:00") #86400 is the number of seconds in one day
df$start.time <- as.POSIXct(df$start.time) 
df$t.seconds <- as.numeric(interval(df$start.time,
                                    df$time)) #rethomics wants elapsed seconds since a ZT0, so we choose the ZT0 
                                              #from the day before and put all values as elapsed seconds since then

#produce behavr table
dt <- behavr(data.table(id=df$id, #DATA TABLE
                        t=df$t.seconds,
                        activity=df$chirp80_r, 
                        key="id"),                        
             data.table(id=metadata$id, #METADATA TABLE    
                        treatment = metadata$treatment,
                        temp = metadata$temp,
                        key="id"))           

dt[is.na(dt$activity),"activity"] <- 0 #convert missing values to zero 

#actogram plot theme
ThemeActo <- theme_bw() +
  theme(
    plot.title = element_blank(),
    axis.title.x = element_blank(),
    axis.title.y = element_blank()) + 
  theme(panel.border = element_blank(), panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank()) +
  theme(legend.position="bottom", legend.text=element_text(size=7)) 

#actogram for an individual cricket
c3_acto <- ggetho(dt, aes(x=t, z=activity), multiplot = 2)+ stat_tile_etho() + 
  stat_ld_annotations(ld_colours = c("white", "black"), 
                      ypos="top") + ThemeActo + labs(fill=NULL) 

#polar coordinate theme
ThemePolCor <- theme_bw() +
  theme(title = element_text(size = 12)) +
  theme(text = element_text(family = "Helvetica")) +
  theme(axis.title.x = element_blank(),
        axis.title.y = element_blank()) +
  theme(legend.position = "none") +
  theme(panel.border = element_blank()) +
  theme(plot.title = element_text(hjust=0.5))

#colour palette
MaryPal <- brewer.pal(n=9, "Reds")

#polar coordinate plot code
c3_polcor <- ggetho(dt, aes(y=as.numeric(activity), fill=as.factor(id)), time_wrap = 86400) +
  stat_ld_annotations(height=.5,
                      alpha=.2,
                      x_limits = c(0, 86400),
                      outline = NA) +
  labs(title = "Cricket 3") +
  stat_pop_etho() + coord_polar() + ThemePolCor + 
  scale_colour_manual(values=MaryPal[8], name=NULL) + 
  guides(fill=FALSE, colour=guide_legend(override.aes=list(fill=NA)))

c3_polcor
c3_acto

stat_pop_etho does draws a line through the plot

This is most likely due to the fact that real world data has animals/experiments starting at different time of the day,. missing data etc. we should ensure the resulting plot is time-sorted.

Plot different days' data on the same graph

Thanks for creating this great tool sets!

I'd like to ask if we could plot the data from different days on the same graph, as shown in the picture below. I tried several ways and found that it's difficult to align the time series from different days, especially when there are some missing data. I really appreciate any of your suggestions.

day1vsday2

stat_ld_annotations with phase != 0

The first LD box does not work in some case of stat_ld_annotation:

rplot

The subsequent boxes are shifted nicely.

library(ggetho)
metadata <- data.table(id=sprintf("toy_experiment|%02d" , 1:40), region_id=1:40,
                   condition=c("A","B"),
                   sex=c("M","M", "F", "F"))
head(metadata)

dt <- toy_activity_data(metadata, seed=107)

pl <- ggetho(dt, aes(x=t, y=moving)) +
            stat_ld_annotations(phase = hours(-1)) +
            stat_pop_etho()
pl

first and last points of stat_stat_etho should join on polar coordinates

One of the issues of #34. Reproducible example:

library(ggetho)
metadata <- data.frame(id = sprintf("toy_experiment | %02d", 1:20),
                       condition = c("A", "B"))
dt <- toy_activity_data(metadata, 3)
pl <-  ggetho(dt, aes(y = asleep), time_wrap = behavr::hours(24), time_offset = behavr::hours(6)) + 
  stat_pop_etho() +coord_polar()   
pl

image

This is absolutely expected since we are drawing a line and a ribbon (and that would look terible on a non_polar coordinate system if the last and first point were joined) and not a polygon. Maybe we add an argument in stat_pop_etho such as close_path=TRUE to force drawing last line?

allow transformtions of time scales

metadata <- data.frame(id = sprintf("toy_experiment | %02d", 1:20),
                   condition = c("A","B"))
dt <- toy_activity_data(metadata, 3)
# Then, a simple plot
pl <-  ggetho(dt, aes(y = asleep)) + stat_pop_etho()
pl + scale_x_hours(breaks = days(c(1, 2)), trans="log10")

gives: unused argument (trans = "log10")

scales should be able to wrap

It would be useful to have the labelers wrap time in the x scales, optionally.
e.g.
scale_x_hours gives breaks at:
[0, 6, 12, 18, 24, 30, 36]
we would get instead:
[0, 6, 12, 18, 0, 6, 12]

ggperio Issue

Hallo everyone,

I am using ggetho to analyze my mouse activity data and so far it is wokring quite fine, except one little issue: when I want to calculate the periodogram with ggperio, it gives me this warning:

50: In optimize(function(par) fn(par, ...)/con$fnscale, lower = lower, ... :
NA/Inf replaced by maximum positive value

I cannot figure out what exactly is the problem and what this warning means. It gives me a periodorgam though.

I would be greatful for any kind of help,
Thank you,
Charly

double plotted actogram

my prototype so far:

image

data("dams_sample")

dt <- data.table::copy(dams_sample)
dt[, t := as.numeric(t)]
sdt <- behavr::bin_apply_all(dt,
                             "activity",
                             x="t",
                             x_bin_length = mins(30),
                             wrap_x_by=NULL,
                             FUN=mean,
                             string_xy=T)


sdt[,day := floor(t/hours(24))]
sdt[,t_in_day := t %% days(1)]

sdt2 <- data.table::copy(sdt)
sdt2[,day := day - 1]

sdt2[,t_in_day := t_in_day + hours(24)]
sdt <- sdt[ day < max(day)]
sdt <- rbind(sdt, sdt2)
sdt <- sdt[day>-1]
sdt[, day := as.ordered(day)]
sdt[, day := ordered(day,levels=rev(levels(day)))]


data.table::setkeyv(sdt, "id")
setbehavr(sdt, dt[, meta = T])


pl<- ggplot(rejoin(sdt),aes(t_in_day,y=day, fill=activity+1)) +
  geom_tile() + facet_wrap( ~ id * period_group, labeller = ggetho::id_labeller)+
  scale_y_discrete(name="starting day") +
  scale_fill_gradient(trans = "log")
pl

How can we export the processed data to csv files?

Thanks for this amazing tools!

I'd like to ask if there are ways to export the calculated data, for example, the binned sleep data or the circadian periodicity data, to csv files.

This is very useful for re-plotting the data in Graphpad, which is much more intuitive to use.

compatibility with ggplot 2.3

Quite a lot of breaking changes in the new ggplot:

Dear Quentin Geissmann,

This is an automated email to let you know that:

* A new version of ggplot2 is ready to go to CRAN. ggplot2 is
  currently at version 2.2.1.9000 and will become 2.3.0 upon release.

* ggetho uses ggplot2 and has problems with the new version.

* We plan to submit ggplot2 to CRAN on June 25.

I need your help to keep ggetho and ggplot2 working together smoothly.
In the next one month, can you please:

1. Read about the changes to ggplot2 at
   https://github.com/tidyverse/ggplot2/blob/master/NEWS.md#ggplot2-2219000.
   This page includes a list of breaking changes, the reasoning behind
   them, and to how to update your code.

2. Carefully inspect the failing checks listed at the bottom of this email.

3. For each failing check, either update your package, or tell me
   that I have a bug. If you have made changes to your package, please
   submit an update to CRAN before June 25.

If you have discovered a bug in ggplot2, please file an issue (ideally
with a small reprex that illustrates the problem) at
https://github.com/tidyverse/ggplot2/issues. If you're not sure
whether or not you've found a bug, please an issue and we'll help you
figure it out.

Thanks,

Hadley Wickham

time_wrap creates error "Incompatible classes: <numeric> %% <Period>"

Hi,

I'm having this problem analysing my own data. I managed to recreate it with the example given in https://rethomics.github.io/ggetho.html

library(damr)
library(dplyr)
library(lubridate)
library(ggetho)
library(ggplot2)
library(sleepr)
library(zeitgebr)

metadata_test <- data.table(id=sprintf("toy_experiment|%02d" , 1:40), region_id=1:40,
                       condition=c("A","B"),
                       sex=c("M","M", "F", "F"))
dt <- toy_activity_data(metadata_test, seed=107)
ggetho(dt, aes(x=t, y=moving, colour=sex)) + stat_pop_etho()#this command works fine
ggetho(dt, aes(x=t, y=moving), time_wrap = hours(24)) + stat_pop_etho()

I then get this error

Error: Incompatible classes: <numeric> %% <Period>

As this is happening with the toy example, I assume it is something to do with other packages perhaps lubridate?

CRAN packages failing examples with \donttest

From cran:

This concerns packages
BayesSUR DCPO cnum dataesgobr ggetho mma nontarget rFIA rsleep trread vimp
Examples in \donttest are run by example() and must work (they should also have an explanatory comment). These packages have 'donttest' Additional issues showing where they fail.
Please correct ASAP and before May 6 to safely retain the package on CRAN.
(In some cases an update was accepted recently which still fails this check, part of R CMD check --as-cran. Make sure you run that with current R-devel before submission.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.