How to make one line color in geom_line to overshadow other line colors?

Viewed 274

I am trying to create a plot that is similar to the one below where the blue color overshadows the gray ones. However, in the plot that i am creating, the blue color is not overshadowing the other colors. Could someone guide me on how that would be possible?

Here is the plot that i would like to get in terms of colors:

enter image description here

Here is my plot:

  ggplot(df, aes(year, unemp), color=cntry)+
  geom_line(aes(group=cntry, color=cntry), size=1.5)+
  scale_color_manual(values=c('dark blue','#999999','#999999','#999999','#999999','#999999'))

enter image description here

And here is my data:

   df= structure(list(cntry = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L), .Label = c("France", 
"Germany", "Italy", "Poland", "Spain", "United Kingdom"), class = "factor"), 
    year = c(2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 
    2010, 2011, 2012, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 
    2009, 2010, 2011, 2012, 2002, 2003, 2004, 2005, 2006, 2007, 
    2008, 2009, 2010, 2011, 2012, 2002, 2003, 2004, 2005, 2006, 
    2007, 2008, 2009, 2010, 2011, 2012, 2002, 2003, 2004, 2005, 
    2006, 2007, 2008, 2009, 2010, 2011, 2012, 2002, 2003, 2004, 
    2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012), unemp = c(8, 
    9, 9, 9, 9, 8, 7, 9, 9, 9, 10, 9, 10, 10, 11, 10, 9, 7, 8, 
    7, 6, 5, 9, 8, 8, 8, 7, 6, 7, 8, 8, 8, 11, 20, 20, 19, 18, 
    14, 10, 7, 8, 10, 10, 10, 11, 11, 11, 9, 8, 8, 11, 18, 20, 
    21, 25, 5, 5, 5, 5, 5, 5, 6, 8, 8, 8, 8)), row.names = c(NA, 
-66L), class = c("tbl_df", "tbl", "data.frame"))
2 Answers

User @stefan had closed this question as a duplicate of this one but I don't believe the dupe answers it. This question ask how to put a line on top of all others, not to just highlight it.

Here is a way. Reverse the factor levels and reverse the legend, in order to have France on top.

library(dplyr)
library(ggplot2)

clrs <- c('dark blue','#999999','#999999','#999999','#999999','#999999')

df %>%
  mutate(cntry = factor(cntry, levels = rev(levels(cntry)))) %>%
  ggplot(aes(year, unemp), color=cntry)+
  geom_line(aes(group=cntry, color=cntry), size=1.5)+
  scale_color_manual(values = rev(clrs),
                     guide = guide_legend(reverse = TRUE))  

enter image description here

You could plot it separately, after the others. Something like this:

ggplot(df, aes(year, unemp), color=cntry)+
  geom_line(aes(group=cntry, color=cntry), size=1.5)+
  geom_line(data = df[df$cntry == 'France',], aes(group=cntry, color=cntry), size=1.5)+
  scale_color_manual(values=c('dark blue','#999999','#999999','#999999','#999999','#999999'))
Related