Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ggetho() multiplot data differs in adjacent rows #38

Open
cabaJr opened this issue Jun 25, 2020 · 3 comments
Open

ggetho() multiplot data differs in adjacent rows #38

cabaJr opened this issue Jun 25, 2020 · 3 comments
Assignees

Comments

@cabaJr
Copy link

cabaJr commented Jun 25, 2020

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?

@qgeissmann qgeissmann self-assigned this Jun 25, 2020
@qgeissmann
Copy link
Contributor

thanks @cabaJr for reporting your issue. that seems like a bug at first glance. is there any chance you could try to reproduce it with a toy dataset? behavr::toy_dam_data() Alternatively, can you send a small subset of your data and code that would allow us to reproduce that :)? thanks

@cabaJr
Copy link
Author

cabaJr commented Jul 7, 2020

files.zip

Here is a simplified version of the code that allows generating a plot. Some issues are already evident in row 6 and 7.
To make it work just download the dataset in the zip file and adjust the code at lines 3, 18, and 21, inserting the datapath from your working directory.

library(tidyverse)
library(behavr)
library(ggetho)
library(stringr)

#get metadata
meta_colnames = c("id", "Cabinet","sex", "gene")
metadata <- read_delim("using/metadata.csv", skip=1, col_names = meta_colnames, delim = ';')#

#set column values and other nonrecurrent operations
columns <- c("day", "hour", "min", "Counts_min", "Lights")
partial <- c("id", "x1", "x2", "x3", "x4")
timeser <- seq(from = 0, by = 60, length.out = 20340)
analysis <- tibble("id" = as.double(),
                   "t" = as.numeric(),
                   "counts_min" = as.numeric(),
                   "Sex" = as.character(),
                   "Gene" = as.character(),
                   "Cabinet" = as.character())

#get data
data <- read_delim("using/clock/01_285_Counts.csv", skip = 1864, col_names = columns, delim = ',')

#get id
sensor_id <- read_delim("using/clock/01_285_Counts.csv", skip = 1, n_max = 1, col_names = partial, delim = ',')
analysis_id = as.double(str_sub(sensor_id$id, 4))

#create tibble of data
analysis <-  tibble("id" = analysis_id,
                 "t" = timeser,
                 "counts_min" = data$Counts_min,
                 "Sex" = metadata$sex,
                 "Gene" = metadata$gene,
                 "Cabinet" = metadata$Cabinet)

#create behavr table
setDT(analysis, key = "id")
setDT(metadata, key = "id")
sum <- behavr(analysis, metadata)

#plot
ggetho(sum, aes(x = t, z=counts_min),
       multiplot = 2,
) +
  stat_ld_annotations(height = 1, alpha = 0.03, outline = NA, phase = 0)+
  stat_bar_tile_etho()+
  facet_wrap(~id+sex+gene, ncol = 6, labeller = label_wrap_gen(multi_line=FALSE))+
  ylab("")+
  ggtitle("Double plotted actogram", subtitle = "splitted by ID")

sorry for taking a long time to provide a simplified working version, hope this will help in solving the issue

@cabaJr
Copy link
Author

cabaJr commented Jul 7, 2020

BONUS QUESTION
I would like to print some points on top of the multiplot. I have a list with the time (x axis) at which these points have to be placed, but I'm struggling to make ggetho interact with generic ggplot2 arguments. Is there any solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants