robinweide / GENOVA

GENome Organisation Visual Analytics
GNU General Public License v3.0
70 stars 15 forks source link

overlay virtual 4C figure #296

Open Moonriver1988 opened 2 years ago

Moonriver1988 commented 2 years ago

Hello,

I'd like to know if there's any way to overlap the virtual 4C figures from two different datasets in Genova? With bundle function seems can display two virtual 4C figures separately at the same time, but how to display two virtual 4C profiles in one single figure? Thank you!

teunbrand commented 2 years ago

Because the plots are ggplot2-based, the visualise() output is still available to be modified further by ggplot2 functions. For example, in the example below, we're removing the facetting by overriding with facet_null().

library(ggplot2)

p <- ggplot(mpg, aes(displ, hwy)) +
  geom_point() +
  facet_grid(year ~ .)
p

p + facet_null()

Created on 2022-05-23 by the reprex package (v2.0.1)

I'd expect this to work very similarly for the visualise output, e.g.:

visualise(your_object) + facet_null()
Moonriver1988 commented 2 years ago

Hello,

Thanks for your reply! It doesn't work by directly adding "facet_null()" after visualise, it shows the following error: Error in check_aesthetics(): ! Aesthetics must be either length 1 or the same as the data (4): fill Run rlang::last_error() to see where the error occurred.

By the way, I'd like to know how to extract virtual 4C result, I think it maybe more flexible to draw the figure by ggplot2 directly without using "visualise" function.

Could you help me with this?

Thank you very much for your help!

teunbrand commented 2 years ago

Sure, the virtual 4C result is under the data element of the result.

library(GENOVA)

exp <- get_test_data("40k", download = TRUE)
exp2 <- get_test_data("40k")

expnames(exp)  <- "bar"
expnames(exp2) <- "foo"

v4c <- virtual_4C(list(exp, exp2), "chr21:30e6:31e6")

head(v4c$data)
#>   chromosome      mid      bar      foo
#> 1      chr21  9500000 4.656886 4.656886
#> 2      chr21  9820000 2.068990 2.068990
#> 3      chr21  9900000 2.224781 2.224781
#> 4      chr21 10420000 3.109784 3.109784
#> 5      chr21 10540000 3.689772 3.689772
#> 6      chr21 10580000 2.857161 2.857161

You can use that with ggplot2, though you might choose to convert to long format first with, for example, tidyr::pivot_longer().

library(ggplot2)
#> 
#> Attaching package: 'ggplot2'
#> The following object is masked from 'package:GENOVA':
#> 
#>     resolution
ggplot(v4c$data, aes(mid)) +
  geom_line(aes(y = foo)) +
  coord_cartesian(ylim = c(NA, 250))

Created on 2022-05-25 by the reprex package (v2.0.1)

Moonriver1988 commented 2 years ago

Thank you very much for your reply! I'm sorry to bothering you again. v4c$data has 3 columns, "chromosome", "mid", "sample_name", I tried using v4c$data to draw figure with ggplot2, but the profile looks different from "visualise" and the Y axis scale is also different from "visualise". Please see the figures below.

visualise(v4c, bedlist = bed_list, 
          bed_colours = c("dodgerblue","red","green","orange"))

visualise

ggplot(v4c$data, aes(mid)) +
  geom_area(aes(y = sample_name))

ggplot2_github

I'd like to know what is the Y axis value in visualise figure? and what is the value in the 3rd column of v4c$data?

Thanks again for your help!

teunbrand commented 2 years ago

what is the Y axis value in visualise figure

The y-axis limits are determined by the natural data limits after the viewpoint itself is excluded.

Another thing to keep in mind if you're using geom_line() or geom_area(): it will show the data as if it was interpolated (which some people might call misleading if not communicated). For example if you have x = c(1, 3), and y = c(2, 6) it will appear as if when x = 2 that y = 4, whereas in actuality the data is missing for x = 2. The visualise() function uses geom_col(), which doesn't appear interpolated.

Moonriver1988 commented 2 years ago

Thanks for your reply and thank you very much for your suggestion about using geom_col()! The ggplot figure do looks like visualise figure after remove viewpoint. I really appreciate you taking time to help me!