I am attempting to generate a UMAP plot with R plotly where you can change how the points are colored by selecting a different variable in the dropdown menu. What I have so far will update how the points are colored, but the colorscale is Red, not the “Set1” color scheme I want, and there is no key displaying what the colors indicate.
This is what I have so far:
vars_df$orig.ident <- as.factor(vars_df$orig.ident)
vars_df$singlr_labels <- as.factor(vars_df$singlr_labels)
# Define dropdown buttons with explicit color mapping
dropdown_buttons <- list(
list(method = "restyle",
args = list("marker.color", list(as.numeric(vars_df$orig.ident))),
label = "orig.ident"),
list(method = "restyle",
args = list("marker.color", list(as.numeric(vars_df$singlr_labels))),
label = "singlr_labels")
)
# Your plot
vars_umap <- plot_ly(data = vars_df,
x = ~UMAP_1,
y = ~UMAP_2,
type = 'scatter',
mode = 'markers',
alpha = 0.7,
marker = list(color = as.numeric(vars_df$orig.ident), colors = "Set1"),
showlegend = TRUE
) %>% layout(
xaxis = list(
tickvals = 'none',
showticklabels = FALSE
),
yaxis = list(
tickvals = 'none',
showticklabels = FALSE
)
) %>%
layout(title = 'UMAP Plot',
updatemenus = list(
list(
buttons = dropdown_buttons,
direction = "down",
showactive = TRUE
)
))
vars_umap
https://i.sstatic.net/HbdfGOyI.png
https://i.sstatic.net/BovHDhzu.png
Nora Kearns is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.