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

Rendering different clusters of points with different colors #213

Open
ghost opened this issue Feb 15, 2022 · 0 comments
Open

Rendering different clusters of points with different colors #213

ghost opened this issue Feb 15, 2022 · 0 comments

Comments

@ghost
Copy link

ghost commented Feb 15, 2022

Hi,

First of all, thank you for the great package!
I would like to visualize single-cell RNA-seq data with rayshader.
In short, there are multiple clusters of points with different colors, and I want them to "jump out" based on the density of cells using geom_bin2d. In short, I have only been able to render one red cluster, but not a blue cluster in the same plot.

Here is a reproducible toy example, adapted from this Stack Overflow post:

library(tidyverse)
library(rayshader)

dfA <- data.frame(x=rnorm(50000, mean=5),  y=rnorm(50000, mean=5))
dfB <- data.frame(x=rnorm(30000, mean=25), y=rnorm(30000, mean=25))

p1 <- ggplot() + theme_bw() +
  geom_bin2d(data=dfA, aes(x=x, y=y), bins=100) +
  scale_fill_gradient(low="white", high="red")

p2 <- ggplot() + theme_bw() +
  geom_bin2d(data=dfB, aes(x=x, y=y), bins=100) + 
  scale_fill_gradient(low="white", high="blue")

p.combined <- ggplot(data = layer_data(p1),
                     aes(x = x, y = y, fill = fill)) +
  geom_tile() +
  geom_tile(data = layer_data(p2)) +
  scale_fill_identity() +
  theme(legend.position = "none", 
        axis.line=element_blank(), 
        axis.text.x=element_blank(), axis.title.x=element_blank(),
        axis.text.y=element_blank(), axis.title.y=element_blank(),
        axis.ticks=element_blank(), 
        panel.background = element_blank())

p.combined looks like this:
Capture

But then I try to render it using rayshader:

plot_gg(p.combined, multicore=TRUE,width=10,height=10,scale=400, windowsize=c(1000, 866),
        offset_edges = TRUE, shadow_intensity = 0.9, shadowcolor = "#3a4f70", lambert=TRUE)

and only one of the clusters renders in 3D, the other stays flat:
Capture2

Perhaps I'm missing something within ggplot or rayshader, and the solution is simple. It probably has to do with using geom_tile(). Any help would be appreciated!

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

0 participants