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

Customizing for opacity of the subcortical structure #21

Open
zhangjb35 opened this issue Jun 27, 2024 · 2 comments
Open

Customizing for opacity of the subcortical structure #21

zhangjb35 opened this issue Jun 27, 2024 · 2 comments

Comments

@zhangjb35
Copy link

zhangjb35 commented Jun 27, 2024

Seem the opacity of subcortical structure cannot control by the opacity parameter of ggseg3d.

library(ggsegDefaultExtra)
library(ggseg3d)
library(dplyr)
library(tidyr)
library(plotly)

# setup region to display
labs <- c("Left-Hippocampus.ant","Left-Hippocampus.post")
aseg_filt <- hcpa_3d |> 
  unnest(ggseg_3d) |> 
  filter(
    # Of you 'dont want the ones in the vector
    label %in% labs
  ) |> 
  as_ggseg3d_atlas()

# setup color for ant and post region
somData_aseg = hcpa_3d %>% 
  unnest(col = ggseg_3d) %>% 
  filter(grepl("Left-Hippocampus.ant|Left-Hippocampus.post", label)) %>% 
  select(label) %>% 
  mutate(myCol = case_when(
    grepl("Left-Hippocampus.ant", label) ~ "#BD1E2D",
    grepl("Left-Hippocampus.post", label) ~ "#fbb041",
  ))

p <- ggseg3d(.data = somData_aseg, atlas = aseg_filt, na.alpha=0.1, show.legend = F, colour = "myCol", alphahull=0,opacity=0.1) %>% 
  add_glassbrain("left") %>%
  pan_camera("left lateral") %>%
  add_trace(x = 50, y = 30, z = 40, type = "scatter3d", mode = "markers", marker = list(color = 'rgb(0,0,0)',size=2), inherit = T, showlegend = F) %>%
  add_trace(x = 50, y = 20, z = 20, type = "scatter3d", mode = "markers", marker = list(color = 'rgb(0,0,0)',size=2), inherit = T, showlegend = F) %>%
  add_trace(x = 40, y = 10, z = 40, type = "scatter3d", mode = "markers", marker = list(color = 'rgb(0,0,0)',size=2), inherit = T, showlegend = F) %>%
  add_trace(x = 30, y = -2, z = 40, type = "scatter3d", mode = "markers", marker = list(color = 'rgb(0,0,0)',size=2), inherit = T, showlegend = F) %>%
  add_trace(x = 20, y = -12, z = 40, type = "scatter3d", mode = "markers", marker = list(color = 'rgb(0,0,0)',size=2), inherit = T, showlegend = F) %>%
  add_trace(x = -21, y = -17, z = -23, type = "scatter3d", mode = "markers", marker = list(color = 'rgb(0,148,68)',size=8), inherit = T, showlegend = F) %>%
  remove_axes()
p
@zhangjb35
Copy link
Author

zhangjb35 commented Jun 27, 2024

Seem just change the op setup in ggseg3d can achieve it.

p = plotly::plot_ly()
    for (tt in 1:nrow(atlas3d)) {
        col = rep(unlist(atlas3d[tt, fill]), nrow(atlas3d$mesh[[tt]]$faces))
        col = ifelse(is.na(col), na.colour, col)
        op = ifelse(is.na(unlist(atlas3d[tt, fill])), na.alpha, 
            0.1)
        txt = if (is.null(text)) {
            text
        }
        else {
            paste0(text, ": ", unlist(atlas3d[tt, text]))
        }
        p = plotly::add_trace(p, x = atlas3d$mesh[[tt]]$vertices$x, 
            y = atlas3d$mesh[[tt]]$vertices$y, z = atlas3d$mesh[[tt]]$vertices$z, 
            i = atlas3d$mesh[[tt]]$faces$i - 1, j = atlas3d$mesh[[tt]]$faces$j - 
                1, k = atlas3d$mesh[[tt]]$faces$k - 1, facecolor = col, 
            type = "mesh3d", text = txt, showscale = FALSE, opacity = op, 
            name = unlist(atlas3d[tt, label]), ...)
    }

@drmowinckels
Copy link
Contributor

Hi! I'm checking in just to say I'm sorry for not following up. I am on long-term sick leave and am not able to deal with maintenance at this point. I will follow up as soon as I am able, and hope someone else might be able to help in the mean time.

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