Troubles with shape=2 for geom_point

First of all, please use appropriate code formatting, your code is very hard to read in this format, see this guide to learn how to do it.

About your question, you are not seeing any point because there are no rows in your dataframe that satisfy those filtering conditions, adding a leggend helps to visualize it, the points that should be (Observed - Mortality - Female) actually are (Observer - Mortality - Male).

library(tidyverse)

trends <- trends %>% 
    mutate(group = paste(Metric, Sex, sep = "-"))

colors = c("Mortality-Male"  = "lightskyblue", "Mortality-Female" = "coral", "Incidence-Female" = "red3", "Incidence-Male" = "navy")
shapes = c("Mortality-Male"  = 1, "Mortality-Female" = 2, "Incidence-Female" = 17, "Incidence-Male" = 16)

ggplot(mapping = aes(Year, Rate, color = group, shape = group)) +
    geom_line(data = trends %>% filter(Type == "Modeled"), size = 1.5, show.legend = FALSE) +
    geom_point(data = trends %>% filter(Type == "Observed"), size = 1.5) +
    labs(x = "Year",
         y = "Rate per 100,000") +
    scale_x_continuous (breaks = c (1991,2004,2017)) +
    scale_y_log10()+
    scale_color_manual(name = "Group", values = colors) +
    scale_shape_manual(name = "Group", values = shapes) +
    theme(legend.position = "bottom",
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank())

3 Likes