Включите выбор трассировки (выделение определенной трассы) для многослойной диаграммы рассеяния, построенной с помощью ggplotly - PullRequest
4 голосов
/ 30 апреля 2019

Я сделал график (с ggplot geom_jitter), используя три разных подмножества одного и того же кадра данных:

  1. Все строки
  2. Строки, где pct.mito > 0.1
  3. Строки, где pct.ribo > 0.3

enter image description here

Я преобразовал объект ggplot в сюжетный объект с помощью ggplotly с намерением сделать каждый слой ggplot (каждый след в plotly объекте) доступным для выбора (в то время как другие два затемняются). Однако это не так, и я не могу понять, почему или как включить функцию «вкл / выкл» для этого графика. Обычно он доступен на других графиках, которые я делаю, используя ggplot + ggplotly.

data <- diff.cells

p <- data %>% ggplot(aes(x = sample, y = nGene, 
                         label.1 = pct.mito, label.2 = pct.ribo, label.3 = nUMI)
                     ) +


# Layer 1: All rows:

geom_point(position = position_jitter(height = 0, width = .2), 
           size = .2, color = "grey50", alpha = 0.4) +

# geom_flat_violin(scale = "width", position = position_nudge(x = .3, y = 0), 
                 # colour = "#35a79c", fill = "#35a79c", alpha = 0.3) +



# Layer 2: pct.ribo >=  0.3 :  

   geom_point(data = data %>% filter(pct.ribo >= 0.3) %>% arrange(pct.ribo), 
           aes(colour = pct.ribo), 
           position = position_jitter(height = 0, width = .2), 
           size = .4, shape = 21, alpha = 0.7) +

  scale_colour_viridis_c(option = "viridis", begin = 0.25, end = 0.9) + 
                        #  limits = c(0.1, 0.5)) +


# Layer 3: pct.ribo >=  0.3

   geom_point(data = data %>% filter(pct.mito >= 0.1) %>% arrange(pct.mito), 
           aes(fill = pct.mito), 
           position = position_jitter(height = 0, width = .2), 
           shape = 21, stroke = 0, size = .8, alpha = 0.7) +

  scale_fill_viridis(option = "inferno", begin = 0.5, end = 0.9) +
                         # limits = c(0.1, 0.5)) + 

  # geom_boxplot(aes(x = as.numeric(sample) + 0.32, group=sample), 
  # colour = "grey50", width = .075, outlier.shape = NA, alpha = 0.3 ) +

  ylim(0, 4000) +

  theme_minimal() +
  theme(axis.text.x = element_text(angle = 30))


# Convert to plotly:

p <- ggplotly(p, tooltip = c("y", paste0("label.", 1:3)))

saveWidget(p, "diffCells.html")

Здесь расположена сюжетная структура объекта:

plotly_json(p) %>% saveWidget("diffCells_plotly_json.html")

https://natalianutella.github.io/examples/diffCells_plotly_json.html

enter image description here

Спасибо.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...