0
votes

I Have data (expanded.plot.dat) that looks like this:

  expanded  UMAP_1  UMAP_2  
a  339       -2.3    -5
b   NA        0.4    2.7
c  3044      -1.2     4
d   NA         3    -5.7

There are a lot of NA values and I would like them to be plotted, however the NA values are obscuring many of the non-NA values, I'm guessing this could be fixed by plotting NA values first.

The expanded column is a factor and I've tried converting it to numeric, sorting, and reverting it back to factor, I've also tried reordering the data in the ggplot object itself, but no matter what order I put the data ggplot seemingly plots independently of that order.

Thanks in advance for any assistance!

The ggplot line:

expanded.plot <- ggplot(expanded.plot.dat, aes(UMAP_1, UMAP_2, color=expanded)) + geom_point()

The output as it stands:

enter image description here

2
How about library(dplyr); expanded.plot <- ggplot(expanded.plot.dat %>% arrange(is.na(expanded)), ...? I think that would put the FALSE (ie, not NA) first and the NA last.Jon Spring
Had to add a desc( after the arrange( but thanks so much for getting me on the right line!Gordon Beattie

2 Answers

0
votes

Perhaps using the fct_explicit_na() function from the forcats package, to change the NAs to something else, might help you with this. Also look into reordering the factors before plotting.

0
votes

Credit to @Jon Spring in the comments, achieved with a slight adjustment:

expanded.plot <- ggplot(expanded.plot.dat %>% arrange(desc(is.na(expanded.plot.dat))), aes(UMAP_1, UMAP_2, color=expanded.plot.dat)) + geom_point()