# Plot highest value points on top of UMAP

**URL:** <https://help.c-moor.org/t/plot-highest-value-points-on-top-of-umap/298>\
**Category:** Code Cookbook\
**Created:** [July 9, 2022, 7:51pm UTC](https://help.c-moor.org/t/plot-highest-value-points-on-top-of-umap/298 "2022-07-09T19:51:56Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![mmccoy](https://avatars.discourse-cdn.com/v4/letter/m/db5fbb/32.png) [@mmccoy](https://help.c-moor.org/u/mmccoy)\
**Post date:** [July 9, 2022, 7:51pm UTC](https://help.c-moor.org/t/plot-highest-value-points-on-top-of-umap/298/1 "2022-07-09T19:51:56Z")

</div>

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.

```auto
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.

 ![original_v_reordered](https://canada1.discourse-cdn.com/flex027/uploads/c_moor/original/1X/140fdf4679b74901dfb58666219248acfc0e3195.png)

---

<div class="post-metadata">

**Author:** ![ShamounDivanyan](https://avatars.discourse-cdn.com/v4/letter/s/a4c791/32.png) [@ShamounDivanyan](https://help.c-moor.org/u/ShamounDivanyan)\
**Post date:** [July 12, 2022, 10:24pm UTC](https://help.c-moor.org/t/plot-highest-value-points-on-top-of-umap/298/2 "2022-07-12T22:24:06Z")

</div>

![image](https://canada1.discourse-cdn.com/flex027/uploads/c_moor/original/1X/d5103077651e1e63afadee4914927bed587cd7dc.jpeg)

 ![Screen Shot 2022-06-16 at 11.55.42 AM](https://canada1.discourse-cdn.com/flex027/uploads/c_moor/original/1X/50a9c96ef51024df7328a5f40f72197334a18f16.jpeg)

oh yeah this really shows quite a large difference

---

<div class="post-metadata">

**Author:** ![Mark\_Sandwich](https://avatars.discourse-cdn.com/v4/letter/m/cab0a1/32.png) [@Mark\_Sandwich](https://help.c-moor.org/u/Mark_Sandwich)\
**Post date:** [July 14, 2022, 4:23am UTC](https://help.c-moor.org/t/plot-highest-value-points-on-top-of-umap/298/3 "2022-07-14T04:23:01Z")

</div>

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.

 ![image](https://canada1.discourse-cdn.com/flex027/uploads/c_moor/original/1X/bd7d49d039261516e5224ea87852951844611b58.png)

I know it’s not necessary for the posters since the images will be so small anyways but I was wondering if you had a fix around this.

---

<div class="post-metadata">

**Author:** ![LindsayHayes](https://yyz1.discourse-cdn.com/flex027/user_avatar/help.c-moor.org/lindsayhayes/32/14_2.png) [@LindsayHayes](https://help.c-moor.org/u/LindsayHayes)\
**Post date:** [July 14, 2022, 12:32pm UTC](https://help.c-moor.org/t/plot-highest-value-points-on-top-of-umap/298/4 "2022-07-14T12:32:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![yanethp](https://avatars.discourse-cdn.com/v4/letter/y/bbce88/32.png) [@yanethp](https://help.c-moor.org/u/yanethp)\
**Post date:** [July 14, 2022, 2:36pm UTC](https://help.c-moor.org/t/plot-highest-value-points-on-top-of-umap/298/5 "2022-07-14T14:36:21Z")

</div>

![Screen Shot 2022-07-14 at 7.33.16 AM](https://canada1.discourse-cdn.com/flex027/uploads/c_moor/original/1X/4221963b8d6a70a216555f623e30979facc1459f.jpeg)  
 ![Screen Shot 2022-07-14 at 7.33.24 AM](https://canada1.discourse-cdn.com/flex027/uploads/c_moor/original/1X/8a1ae133822e12b0e427daad5fea2d51de3f8743.png)  
I’m having trouble making this code work for co-expressed genes. I have my R notebook saved under the su22 public folder.

---

<div class="post-metadata">

**Author:** ![LindsayHayes](https://yyz1.discourse-cdn.com/flex027/user_avatar/help.c-moor.org/lindsayhayes/32/14_2.png) [@LindsayHayes](https://help.c-moor.org/u/LindsayHayes)\
**Post date:** [July 14, 2022, 3:06pm UTC](https://help.c-moor.org/t/plot-highest-value-points-on-top-of-umap/298/6 "2022-07-14T15:06:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![yanethp](https://avatars.discourse-cdn.com/v4/letter/y/bbce88/32.png) [@yanethp](https://help.c-moor.org/u/yanethp)\
**Post date:** [July 14, 2022, 3:28pm UTC](https://help.c-moor.org/t/plot-highest-value-points-on-top-of-umap/298/7 "2022-07-14T15:28:28Z")

</div>

![Screen Shot 2022-07-14 at 8.26.50 AM](https://canada1.discourse-cdn.com/flex027/uploads/c_moor/original/1X/7fb30c17a56182446d21a158c1ef415830a599dd.jpeg)  
 ![Screen Shot 2022-07-14 at 8.26.57 AM](https://canada1.discourse-cdn.com/flex027/uploads/c_moor/original/1X/5819559e9cb95252ec200582d0154b347d0eebfc.jpeg)  
Thank you! It worked but this [blue] is how it turned out in comparison to the original UMAP [orange].

---

<div class="post-metadata">

**Author:** ![LindsayHayes](https://yyz1.discourse-cdn.com/flex027/user_avatar/help.c-moor.org/lindsayhayes/32/14_2.png) [@LindsayHayes](https://help.c-moor.org/u/LindsayHayes)\
**Post date:** [July 14, 2022, 3:40pm UTC](https://help.c-moor.org/t/plot-highest-value-points-on-top-of-umap/298/8 "2022-07-14T15:40:39Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![mmccoy](https://avatars.discourse-cdn.com/v4/letter/m/db5fbb/32.png) [@mmccoy](https://help.c-moor.org/u/mmccoy)\
**Post date:** [July 14, 2022, 6:19pm UTC](https://help.c-moor.org/t/plot-highest-value-points-on-top-of-umap/298/9 "2022-07-14T18:19:34Z")

</div>

Here would be my solution, @yanethp

```auto
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.

---

<div class="post-metadata">

**Author:** ![yanethp](https://avatars.discourse-cdn.com/v4/letter/y/bbce88/32.png) [@yanethp](https://help.c-moor.org/u/yanethp)\
**Post date:** [July 14, 2022, 8:43pm UTC](https://help.c-moor.org/t/plot-highest-value-points-on-top-of-umap/298/10 "2022-07-14T20:43:29Z")

</div>

![Revised UMAP](https://canada1.discourse-cdn.com/flex027/uploads/c_moor/original/1X/6a1975e7901179283f4fc7a5581004d117632af7.jpeg)  
Thank you! That worked.

---

<div class="post-metadata">

**Author:** ![yanethp](https://avatars.discourse-cdn.com/v4/letter/y/bbce88/32.png) [@yanethp](https://help.c-moor.org/u/yanethp)\
**Post date:** [July 14, 2022, 8:48pm UTC](https://help.c-moor.org/t/plot-highest-value-points-on-top-of-umap/298/11 "2022-07-14T20:48:36Z")

</div>

@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.
