Have you ever tried plotting a UMAP with gene expression data only to be frustrated that cells expressing your gene of interest are buried beneath all the other cells? Here’s some code you can use to replot a ggplot with the cells plotted in order of their expression values.
gene <- "ENSMUSG00000033227"
g <- plotReducedDim(sce, dimred = "umap", colour_by = gene)
g %>%
pluck("data") %>%
arrange(colour_by) %>%
ggplot(aes(x = X, y = Y, col = colour_by)) +
geom_point(alpha = 0.6) +
theme_classic() +
scale_color_viridis_c(name = gene) +
xlab("UMAP1") +
ylab("UAMP2")
On the left is the original plot, and on the right is our new plot with points ordered by expression values.
Hi Matt, I’ve also seen the major difference with this method, which I’ll probably be using throughout the end of the following weeks. One issue I’ve had is when I tried running it in the Console, which would create a larger image and more detailed image, I get this error.
It is a Warning not an Error this is an important distinction because an Error means the code could not run. A warning is just letting you know something happened but the code still ran. In this case its just saying 23K cells didn’t have a value for the expression. This is totally fine it just left those cells out of the plot. There isn’t a way to fix this because it is in the way the dataset was generated.
try removing line 146. The color is variable is “double” or “not double” and the scale_color… variable is looking for numeric values. Let me know if that works.
First check the number of cells in the lefty.colors object using the table function.
Second, it also might be putting the “not double” on top I’m not sure how id decides the ordering.
Third you could play around with the colors maybe a brighter color would help? scale_color_manual(levels = c("red", "grey")) +
you could add this to line 46 instead to color the dots red and grey so maybe the red stands out more. You can change the colors too, the order is alphabetical so red = double, grey = not double. You can google image “ggplot2 colors” and find a cheatsheet for the correct names of the colors accepted here. I usually keep it on my computer and reference it often when I’m playing around with colors.
The problem is probably the second one. …
quick fix would be to change the alphabetical order of “double” and “not double”.
For example, change double = b, not double = a (you can also try the reverse, plot both, to check if this is the problem).
g %>%
pluck("data") %>%
arrange(desc(colour_by)) %>%
ggplot(aes(x = X, y = Y, col = colour_by)) +
geom_point(alpha = 0.6) +
theme_classic() +
scale_color_viridis_d(name = "Leftys") +
xlab("UMAP1") +
ylab("UAMP2")
By using arrange(desc(colour_by)), you can order the points by reverse alphabetical order (descending).
By using scale_color_viridis_d() instead of scale_color_viridis_c(), you use a discrete color scale instead of a continuous one.
@LindsayHayes@mmccoy
Is there a way to plot these particular cells over stages? I would like to see if the co-expression of the Lefty genes diminish over time.