How can I omit missing values entry from a legend by overriding the legend?

Viewed 41

I have been struggling with getting this dotplot perfect for weeks now. I fixed many other issues with 2 legends but I now have a new problem I cant work out, which is this extra legend entry for missing values.

How do I override the legend entry to remove it? Or change my code so I just have the 5 variables on the second legend?

Also, is there a way to reorder the y axis to make the graphic more aesthetically pleasing?

Here is my code;

#### Preferences Graphics ######
##################################################

library(tidyverse)
library(ggplot2)

OrNes <-read.csv('NEW2_BodyPref.csv', header = TRUE)    


names(OrNes)


theme_dotplot <- theme_bw(14) +
  theme(axis.text.y = element_text(size = 10.0), 
        axis.ticks.y = element_blank(),
        axis.title.x = element_text(size = 14.0), 
        panel.grid.major.x = element_blank(),
        panel.grid.major.y = element_line(size = 0.5),
        panel.grid.minor.x = element_blank())

BodySize <- OrNes %>%
  filter(!is.na(`Mo`)) %>%
  sample_n(25) %>%
  gather(key = "Class", value = "Mean", "De", "In", 
         "Mo", "Null_Un", "Ma")

BodySize

BodySize$outlier <- BodySize$Mean > 0.4

Trial <- ggplot(BodySize, na.omit = T, aes(Mean, `ï..Latin`, fct_reorder2(`ï..Latin`, Class=="Mo", 
Mean, .desc = TRUE), black=Class, shape = Class)) +
  geom_point() +  ggtitle("Preferences") + ylab("Species") + xlab("Manly's Alpha (a)") +
  theme_dotplot + geom_vline(aes(xintercept = Intercept, linetype = Intercept_names), key_glyph = 
draw_key_path) +
  scale_linetype(name = "Alpha Preference Thresholds") 


print (Trial)    # Plot graph

Trial <- ggplot(BodySize, na.omit = T, aes(Mean, `ï..Latin`, fct_reorder2(`ï..Latin`, Class=="Mo", 
Mean, .desc = TRUE), black=Class, shape = Class)) +
  geom_point() +  ggtitle("Preferences") + ylab("Tree Species") + xlab("Manly's Alpha (a)") +
  theme_dotplot + geom_vline(aes(xintercept = Intercept, linetype = Intercept_names), key_glyph = 
draw_key_path) +
  scale_linetype(name = "Alpha Preference Thresholds") + facet_grid(~ outlier, scale = "free_x", 
space = "free_x") +
  guides(fill=guide_legend(title="Alpha preference thresholds")) +
  theme(axis.text = element_text(face = "italic"),
        strip.text = element_blank(),
        strip.background = element_blank())

print (Trial)    # Plot graph

This is the plot I get. The problem is on the Alpha Preference Thresholds legend

0 Answers
Related