Troubles with shape=2 for geom_point

Hi,

I'm trying to figure out why shape=2 for geom_point (data = trends %>% filter (Metric == "Mortality") %>% filter (Type == "Observed") %>% filter (Sex == "Female") is not working.

Here is the code:
ggplot (mapping = aes (Year, Rate)) + geom_line (data = trends %>% filter (Metric == "Mortality") %>% filter (Type == "Modeled") %>% filter (Sex == "Male"), color = "lightskyblue", size = 1.5) + geom_point (data = trends %>% filter (Metric == "Mortality") %>% filter (Type == "Observed") %>% filter (Sex == "Male"), color = "lightskyblue", size = 1.5, shape = 1) + geom_line (data = trends %>% filter (Metric == "Incidence") %>% filter (Type == "Modeled") %>% filter (Sex == "Male"), color = "navy", size = 1.5) + geom_point (data = trends %>% filter (Metric == "Incidence") %>% filter (Type == "Observed") %>% filter (Sex == "Male"), color = "navy", size = 1.5, shape = 16) + geom_line (data = trends %>% filter (Metric == "Mortality") %>% filter (Type == "Modeled") %>% filter (Sex == "Female"), color = "coral", size = 1.5) + geom_point (data = trends %>% filter (Metric == "Mortality") %>% filter (Type == "Observed") %>% filter (Sex == "Female"), color = "coral", size =1.5, shape =2) + geom_line (data = trends %>% filter (Metric == "Incidence") %>% filter (Type == "Modeled") %>% filter (Sex == "Female"), color = "red3", size = 1.5) + geom_point (data = trends %>% filter (Metric == "Incidence") %>% filter (Type == "Observed") %>% filter (Sex == "Female"), color = "red3", size = 1.5, shape = 17) + scale_x_continuous (breaks = c (1991,2004,2017)) + xlab ("Year") + ylab ("Rate per 100,000")+theme(legend.position = "none")+theme(panel.grid.major = element_blank(),panel.grid.minor = element_blank())+scale_y_log10()

And here is the data frame:

data.frame(stringsAsFactors=FALSE,

  •     Year = c(1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
    
  •              2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
    
  •              2011, 2012, 2013, 2014, 2015, 2016, 2017, 1991, 1992, 1993, 1994,
    
  •              1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
    
  •              2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015,
    
  •              2016, 2017, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
    
  •              2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
    
  •              2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 1991, 1992, 1993,
    
  •              1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
    
  •              2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014,
    
  •              2015, 2016, 2017, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
    
  •              2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015,
    
  •              2016, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
    
  •              2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016,
    
  •              1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
    
  •              2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 1997,
    
  •              1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
    
  •              2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016),
    
  •     Rate = c(67, 63.1, 87.8, 72.9, 80, 77.6, 98, 108.2, 84.1, 104.4, 83.6,
    
  •              93.2, 105.3, 72.6, 83.9, 74.2, 72, 68.4, 101.3, 100.2, 87.9,
    
  •              102.2, 105.5, 81.2, 80.7, 98.7, 69.6, 7.6, 9.7, 11.6, 7.9, 11.2,
    
  •              9.8, 9.8, 4.2, 8.2, 8.1, 7.1, 8.4, 6.3, 10.8, 5.5, 7.5, 7.6,
    
  •              8.2, 15.9, 7.7, 6.9, 9.1, 16.8, 11.6, 12.5, 14.6, 9.8, 82.48,
    
  •              82.81, 83.15, 83.49, 83.84, 84.18, 84.52, 84.87, 85.22, 85.57, 85.92,
    
  •              86.27, 86.62, 86.98, 87.33, 87.69, 88.05, 88.41, 88.77, 89.13,
    
  •              89.5, 89.87, 90.23, 90.6, 90.97, 91.35, 91.72, 7.94, 8.06, 8.18,
    
  •              8.31, 8.44, 8.56, 8.7, 8.83, 8.96, 9.1, 9.24, 9.38, 9.53, 9.67,
    
  •              9.82, 9.97, 10.12, 10.28, 10.43, 10.59, 10.76, 10.92, 11.09,
    
  •              11.26, 11.43, 11.6, 11.78, 6.6, 5.6, 6.1, 10.2, 6, 8.3, 8.3, 8.3,
    
  •              10.2, 10.4, 11.8, 16.1, 14.8, 8.2, 10.7, 19, 20.6, 16, 15.8,
    
  •              13.7, 101.3, 106.8, 104.6, 102.3, 89.9, 99.6, 106.3, 84.2, 95.7,
    
  •              84.4, 87.3, 77.3, 109.6, 115.7, 102.1, 102.1, 91.1, 94.8, 92.3,
    
  •              109.1, 6.49, 6.86, 7.25, 7.66, 8.1, 8.56, 9.05, 9.57, 10.11,
    
  •              10.69, 11.3, 11.94, 12.62, 13.34, 14.1, 14.91, 15.76, 16.66, 17.6,
    
  •              18.61, 98.57, 98.54, 98.52, 98.5, 98.48, 98.45, 98.43, 98.41,
    
  •              98.39, 98.36, 98.34, 98.32, 98.3, 98.27, 98.25, 98.23, 98.21, 98.18,
    
  •              98.16, 98.14),
    
  •     Site = c("C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34",
    
  •              "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34",
    
  •              "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34",
    
  •              "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34",
    
  •              "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34",
    
  •              "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34",
    
  •              "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34",
    
  •              "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34",
    
  •              "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34",
    
  •              "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34",
    
  •              "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34",
    
  •              "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34",
    
  •              "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34",
    
  •              "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34",
    
  •              "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34",
    
  •              "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34",
    
  •              "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34",
    
  •              "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34",
    
  •              "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34",
    
  •              "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34",
    
  •              "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34",
    
  •              "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34",
    
  •              "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34",
    
  •              "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34",
    
  •              "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34",
    
  •              "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34",
    
  •              "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34",
    
  •              "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34",
    
  •              "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34",
    
  •              "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34",
    
  •              "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34",
    
  •              "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34", "C33-C34",
    
  •              "C33-C34", "C33-C34", "C33-C34"),
    
  •     Type = c("Observed", "Observed", "Observed", "Observed", "Observed",
    
  •              "Observed", "Observed", "Observed", "Observed", "Observed",
    
  •              "Observed", "Observed", "Observed", "Observed", "Observed",
    
  •              "Observed", "Observed", "Observed", "Observed", "Observed",
    
  •              "Observed", "Observed", "Observed", "Observed", "Observed", "Observed",
    
  •              "Observed", "Observed", "Observed", "Observed", "Observed",
    
  •              "Observed", "Observed", "Observed", "Observed", "Observed",
    
  •              "Observed", "Observed", "Observed", "Observed", "Observed", "Observed",
    
  •              "Observed", "Observed", "Observed", "Observed", "Observed",
    
  •              "Observed", "Observed", "Observed", "Observed", "Observed",
    
  •              "Observed", "Observed", "Modeled", "Modeled", "Modeled", "Modeled",
    
  •              "Modeled", "Modeled", "Modeled", "Modeled", "Modeled", "Modeled",
    
  •              "Modeled", "Modeled", "Modeled", "Modeled", "Modeled", "Modeled",
    
  •              "Modeled", "Modeled", "Modeled", "Modeled", "Modeled", "Modeled",
    
  •              "Modeled", "Modeled", "Modeled", "Modeled", "Modeled",
    
  •              "Modeled", "Modeled", "Modeled", "Modeled", "Modeled", "Modeled",
    
  •              "Modeled", "Modeled", "Modeled", "Modeled", "Modeled", "Modeled",
    
  •              "Modeled", "Modeled", "Modeled", "Modeled", "Modeled", "Modeled",
    
  •              "Modeled", "Modeled", "Modeled", "Modeled", "Modeled", "Modeled",
    
  •              "Modeled", "Modeled", "Modeled", "Observed", "Observed",
    
  •              "Observed", "Observed", "Observed", "Observed", "Observed", "Observed",
    
  •              "Observed", "Observed", "Observed", "Observed", "Observed",
    
  •              "Observed", "Observed", "Observed", "Observed", "Observed",
    
  •              "Observed", "Observed", "Observed", "Observed", "Observed", "Observed",
    
  •              "Observed", "Observed", "Observed", "Observed", "Observed",
    
  •              "Observed", "Observed", "Observed", "Observed", "Observed",
    
  •              "Observed", "Observed", "Observed", "Observed", "Observed", "Observed",
    
  •              "Modeled", "Modeled", "Modeled", "Modeled", "Modeled",
    
  •              "Modeled", "Modeled", "Modeled", "Modeled", "Modeled", "Modeled",
    
  •              "Modeled", "Modeled", "Modeled", "Modeled", "Modeled", "Modeled",
    
  •              "Modeled", "Modeled", "Modeled", "Modeled", "Modeled", "Modeled",
    
  •              "Modeled", "Modeled", "Modeled", "Modeled", "Modeled", "Modeled",
    
  •              "Modeled", "Modeled", "Modeled", "Modeled", "Modeled", "Modeled",
    
  •              "Modeled", "Modeled", "Modeled", "Modeled", "Modeled"),
    
  •      Sex = c("Male", "Male", "Male", "Male", "Male", "Male", "Male",
    
  •              "Male", "Male", "Male", "Male", "Male", "Male", "Male",
    
  •              "Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male",
    
  •              "Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male",
    
  •              "Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male",
    
  •              "Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male",
    
  •              "Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male",
    
  •              "Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male",
    
  •              "Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male",
    
  •              "Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male",
    
  •              "Male", "Male", "Male", "Female", "Female", "Female", "Female",
    
  •              "Female", "Female", "Female", "Female", "Female", "Female", "Female",
    
  •              "Female", "Female", "Female", "Female", "Female", "Female",
    
  •              "Female", "Female", "Female", "Female", "Female", "Female",
    
  •              "Female", "Female", "Female", "Female", "Female", "Female", "Female",
    
  •              "Female", "Female", "Female", "Female", "Female", "Female",
    
  •              "Female", "Female", "Female", "Female", "Female", "Female", "Female",
    
  •              "Female", "Female", "Female", "Female", "Male", "Male", "Male",
    
  •              "Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male",
    
  •              "Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male",
    
  •              "Male", "Female", "Female", "Female", "Female", "Female",
    
  •              "Female", "Female", "Female", "Female", "Female", "Female", "Female",
    
  •              "Female", "Female", "Female", "Female", "Female", "Female",
    
  •              "Female", "Female", "Male", "Male", "Male", "Male", "Male", "Male",
    
  •              "Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male",
    
  •              "Male", "Male", "Male", "Male", "Male", "Male"),
    
  •   Metric = c("Mortality", "Mortality", "Mortality", "Mortality",
    
  •              "Mortality", "Mortality", "Mortality", "Mortality",
    
  •              "Mortality", "Mortality", "Mortality", "Mortality", "Mortality",
    
  •              "Mortality", "Mortality", "Mortality", "Mortality", "Mortality",
    
  •              "Mortality", "Mortality", "Mortality", "Mortality", "Mortality",
    
  •              "Mortality", "Mortality", "Mortality", "Mortality", "Mortality",
    
  •              "Mortality", "Mortality", "Mortality", "Mortality", "Mortality",
    
  •              "Mortality", "Mortality", "Mortality", "Mortality", "Mortality",
    
  •              "Mortality", "Mortality", "Mortality", "Mortality", "Mortality",
    
  •              "Mortality", "Mortality", "Mortality", "Mortality", "Mortality",
    
  •              "Mortality", "Mortality", "Mortality", "Mortality", "Mortality",
    
  •              "Mortality", "Mortality", "Mortality", "Mortality", "Mortality",
    
  •              "Mortality", "Mortality", "Mortality", "Mortality", "Mortality",
    
  •              "Mortality", "Mortality", "Mortality", "Mortality",
    
  •              "Mortality", "Mortality", "Mortality", "Mortality", "Mortality",
    
  •              "Mortality", "Mortality", "Mortality", "Mortality", "Mortality",
    
  •              "Mortality", "Mortality", "Mortality", "Mortality", "Mortality",
    
  •              "Mortality", "Mortality", "Mortality", "Mortality", "Mortality",
    
  •              "Mortality", "Mortality", "Mortality", "Mortality", "Mortality",
    
  •              "Mortality", "Mortality", "Mortality", "Mortality", "Mortality",
    
  •              "Mortality", "Mortality", "Mortality", "Mortality", "Mortality",
    
  •              "Mortality", "Mortality", "Mortality", "Mortality", "Mortality",
    
  •              "Mortality", "Incidence", "Incidence", "Incidence", "Incidence",
    
  •              "Incidence", "Incidence", "Incidence", "Incidence", "Incidence",
    
  •              "Incidence", "Incidence", "Incidence", "Incidence", "Incidence",
    
  •              "Incidence", "Incidence", "Incidence", "Incidence", "Incidence",
    
  •              "Incidence", "Incidence", "Incidence", "Incidence",
    
  •              "Incidence", "Incidence", "Incidence", "Incidence", "Incidence",
    
  •              "Incidence", "Incidence", "Incidence", "Incidence", "Incidence",
    
  •              "Incidence", "Incidence", "Incidence", "Incidence", "Incidence",
    
  •              "Incidence", "Incidence", "Incidence", "Incidence", "Incidence",
    
  •              "Incidence", "Incidence", "Incidence", "Incidence", "Incidence",
    
  •              "Incidence", "Incidence", "Incidence", "Incidence", "Incidence",
    
  •              "Incidence", "Incidence", "Incidence", "Incidence", "Incidence",
    
  •              "Incidence", "Incidence", "Incidence", "Incidence", "Incidence",
    
  •              "Incidence", "Incidence", "Incidence", "Incidence", "Incidence",
    
  •              "Incidence", "Incidence", "Incidence", "Incidence", "Incidence",
    
  •              "Incidence", "Incidence", "Incidence", "Incidence", "Incidence",
    
  •              "Incidence", "Incidence")
    
  • )

Do I need to submit a new reprex for this?

Let me know.

Thanks,
Gonçalo

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

Hi,

Thank you so much for your help. I'm sorry that I've not submitted things correctly. I'm still giving baby steps with R. Will get back to the original data to fix it.

Gonçalo

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.