Home > OS >  how can I change the plot order and width of just one line in geom_line
how can I change the plot order and width of just one line in geom_line

Time:12-05

I am trying to map the per capita healthcare spending by province. I would like the Canadian Average line to be a different color and width and plotted on top. I don't want to change the factor order to make it be plotted last, as the factor order is related to the numerical values.

Here is my 'raw' working code and plot, however I'd like to move the average to the top.

color_count<-length(levels(TabB42_melt$variable))
gg_color_hue <- function(n) {
  hues = seq(15, 375, length = n   1)
  hcl(h = hues, l = 65, c = 100)[1:n]
}
col.pal<-gg_color_hue(color_count-1)
col.pal_wB<-c(col.pal[1:10],"black",col.pal[11:length(col.pal)])
# working plot        
main.plot.right.bottom<-ggplot(TabB42_melt, 
                                     aes(x=Year, y=value, group=variable, color=variable,size=variable)) 
      geom_line() 
     scale_size_manual(values=c(rep(1,10),3,rep(1,3))) 
      scale_color_manual(values=col.pal_wB) 
    #  geom_line(data=subset(TabB42_melt,variable=="Average"),aes(x=Year,y=value,size=3,color="black")) 
      ylab("per capita health care spending (CDN)") 
      ggtitle("Per capita spending is increasing over the years") 
      labs(colour="Province") 
      guides(size=FALSE) 
      theme_bw()

enter image description here

So I tried two different layers of geom_line to get the average on top, but I think this is messing with the color scale of the lines. As I get this error "Error: Insufficient values in manual scale. 15 needed but only 14 provided." I have 14 variables. I tried adding 'black" to the end of the scale_color_manual but that didn't work.

Any help appreciated. Thanks

##  Here is one of my attempts to change the width and plotting order of the 'Average' variable  
main.plot.right.bottomv2<-ggplot() 
      # geom_line(lwd=c(rep(1,9),2,rep(1,4))) 
      geom_line(data=TabB42_melt, 
                aes(x=Year, y=value, group=variable, color=variable)) 
      #scale_size_manual(values=c(rep(1,10),3,rep(1,3))) 
      scale_color_manual(values=col.pal_wB) 
      geom_line(data=subset(TabB42_melt,variable="Average"), 
                aes(x=Year, y=value, color="black",size=3)) 
      #  geom_line(data=subset(TabB42_melt,variable=="Average"),aes(x=Year,y=value,size=3,color="black")) 
      ylab("per capita health care spending (CDN)") 
      ggtitle("Per capita spending is increasing over the years") 
      labs(colour="Province") 
      guides(size=FALSE) 
      theme_bw()

Here's my data:

> dput(TabB42_melt)
structure(list(Year = c(1975, 1976, 1977, 1978, 1979, 1980, 1981, 
1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 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, 2018, 2019, 2020, 2021, 1975, 1976, 1977, 1978, 
1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 
1990, 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, 2018, 2019, 2020, 2021, 1975, 
1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 
1987, 1988, 1989, 1990, 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, 2018, 2019, 
2020, 2021, 1975, 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 
1984, 1985, 1986, 1987, 1988, 1989, 1990, 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, 2018, 2019, 2020, 2021, 1975, 1976, 1977, 1978, 1979, 1980, 
1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 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, 2018, 2019, 2020, 2021, 1975, 1976, 1977, 
1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 
1989, 1990, 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, 2018, 2019, 2020, 2021, 
1975, 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 
1986, 1987, 1988, 1989, 1990, 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, 2018, 
2019, 2020, 2021, 1975, 1976, 1977, 1978, 1979, 1980, 1981, 1982, 
1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 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, 2018, 2019, 2020, 2021, 1975, 1976, 1977, 1978, 1979, 
1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 
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, 2018, 2019, 2020, 2021, 1975, 1976, 
1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 
1988, 1989, 1990, 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, 2018, 2019, 2020, 
2021, 1975, 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 
1985, 1986, 1987, 1988, 1989, 1990, 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, 
2018, 2019, 2020, 2021, 1975, 1976, 1977, 1978, 1979, 1980, 1981, 
1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 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, 2018, 2019, 2020, 2021, 1975, 1976, 1977, 1978, 
1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 
1990, 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, 2018, 2019, 2020, 2021, 1975, 
1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 
1987, 1988, 1989, 1990, 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, 2018, 2019, 
2020, 2021), variable = structure(c(4L, 4L, 4L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 
7L, 7L, 7L, 7L, 7L, 7L, 7L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 13L, 
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 
13L, 13L, 13L, 13L, 13L, 13L, 13L, 10L, 10L, 10L, 10L, 10L, 10L, 
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
10L, 10L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 
9L, 9L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 
8L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 11L, 11L, 11L, 11L, 11L, 
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 
11L, 11L, 11L), .Label = c("Nun.", "N.W.T", "Y.T.", "N.L.", "N.S.", 
"Que.", "P.E.I.", "Alta.", "Sask.", "Man.", "Average", "B.C.", 
"Ont.", "N.B."), class = "factor"), value = c(357.92, 389.23, 
412.98, 455.02, 521.43, 588.11, 683.86, 805, 890.49, 921.67, 
969.15, 1060.54, 1147.31, 1216.36, 1302.73, 1447.9, 1485.43, 
1518.73, 1518.77, 1571.25, 1631.09, 1654.49, 1757.47, 1945.49, 
2232.1, 2361.57, 2554.73, 2739.82, 2889.46, 2973.8, 3093.19, 
3311.42, 3671.78, 3908.81, 4262.7, 4676.92, 4950.97, 5347.52, 
5429.27, 5449.55, 5637.18, 5723.97, 5799.18, 5989.03, 6358.77, 
6615.43, 6988.86, 352.59, 382.68, 419.5, 463.22, 508.78, 586.83, 
680.54, 796.93, 875.34, 920.53, 963.5, 1025.46, 1107.45, 1189.14, 
1253.34, 1331.76, 1454.39, 1499.89, 1552.83, 1502.18, 1511.41, 
1570.6, 1571.72, 1684.94, 1766.79, 1892.16, 2232.42, 2516.12, 
2583.01, 2525.88, 2689.21, 2797.3, 3042.09, 3261.94, 3638.25, 
3954.96, 4286.26, 4353.91, 4394.23, 4398.63, 4494.02, 4594.66, 
4705.94, 4843.34, 4997.89, 5178.54, 5433.98, 322.88, 362.39, 
398.29, 438.04, 486.34, 556.45, 669.59, 771.39, 839.18, 912.11, 
979.28, 1031.39, 1104.92, 1194.41, 1304.32, 1387.83, 1457.77, 
1475.64, 1431.86, 1381.14, 1403.47, 1414.88, 1664.5, 1777.72, 
1873.81, 1914.85, 2021.54, 2204.23, 2421.85, 2513.27, 2747.41, 
3044.14, 3311.35, 3457.21, 3610.8, 3973.09, 4220.21, 4332.4, 
4388.16, 4474.65, 4567.14, 4555.62, 4650.35, 4771.47, 4953.03, 
5424.16, 5702.53, 300.87, 351.6, 390.49, 427.56, 478.8, 559.39, 
676.9, 819.26, 877.41, 932.06, 982.59, 1047.13, 1151.39, 1233.45, 
1334.73, 1428.3, 1478.19, 1527.04, 1542.11, 1585.33, 1644.86, 
1640.92, 1613.12, 1691.45, 1824.89, 1955.5, 2129.81, 2240.94, 
2392.4, 2605.2, 2849.55, 3145.79, 3357.47, 3521.85, 3716.34, 
3884.34, 4075.05, 4195.99, 4191.83, 4184.63, 4311.75, 4363.55, 
4446.99, 4533.38, 4613.65, 4781.31, 4946.3, 399.86, 464.68, 508.18, 
568.57, 632.25, 708.24, 804.64, 927.13, 1020.88, 1080.57, 1136.73, 
1150.14, 1217.62, 1315.9, 1390.82, 1474.49, 1607.51, 1648.57, 
1657.31, 1676.15, 1685.96, 1649.61, 1672.38, 1799.5, 1844.39, 
1969.32, 2098.4, 2196.37, 2290.48, 2416.1, 2525.49, 2689.59, 
2900.32, 3012.24, 3202.49, 3312.79, 3418.21, 3483.25, 3607.15, 
3673.01, 4009.56, 4031.53, 4185.75, 4384.73, 4563.7, 5480.08, 
5437.07, 377.83, 429.35, 462.03, 492.35, 527.1, 590.51, 688.8, 
796.42, 887.12, 962.82, 1048.64, 1165.07, 1266.18, 1380.58, 1492.51, 
1573.06, 1720.9, 1779.22, 1741.64, 1733.36, 1694.01, 1686.97, 
1698.1, 1770.37, 1876.86, 2049.18, 2122.92, 2253.33, 2481.04, 
2636.77, 2788.45, 2928.65, 3170.64, 3306.74, 3487.16, 3617.1, 
3697.06, 3833.5, 3884.51, 3960.19, 4024.97, 4059.16, 4136.26, 
4237.47, 4337.11, 4889.25, 5042.08, 367.52, 435.49, 479.36, 504.31, 
549.26, 631.07, 756.03, 875.47, 963.68, 1028.27, 1092.5, 1163.15, 
1242.52, 1328.95, 1437.74, 1576.56, 1612.06, 1678.65, 1661.39, 
1657.61, 1685.66, 1695.27, 1739.74, 1848.64, 2096.61, 2293.04, 
2426.56, 2562.86, 2767.71, 2928.95, 3138.72, 3300.67, 3499.03, 
3702.16, 3960.29, 4119.05, 4245.72, 4433.22, 4571.21, 4550.51, 
4714.38, 4721.15, 4748.52, 4760.18, 4825.88, 5215.87, 5274.97, 
329.31, 390.82, 434.85, 468.12, 529.79, 624.78, 727.41, 870.71, 
964.38, 1008.2, 1074.5, 1189.28, 1224.32, 1312.28, 1471.6, 1623.81, 
1653.71, 1629.43, 1528.81, 1545.72, 1573.25, 1606.99, 1718.43, 
1823.56, 1971.33, 2083.39, 2279.61, 2416.3, 2560.15, 2759.2, 
3026.39, 3238.31, 3494.44, 3684.94, 3852.33, 4064.65, 4264.8, 
4401.23, 4581.07, 4652.92, 4783.14, 4893.97, 4926.76, 4855.19, 
5014.29, 5370.49, 5330.25, 384.21, 434.15, 451.21, 504.61, 600, 
689.25, 816.76, 1023.82, 1156.99, 1187.79, 1262.24, 1363.31, 
1355.29, 1395.33, 1518.19, 1587.17, 1635.98, 1711.66, 1669.19, 
1519.48, 1427.96, 1474.27, 1599.95, 1688.81, 1910.49, 2068.73, 
2300.06, 2471.17, 2603.45, 2812.99, 3069.91, 3290.63, 3615.13, 
3820.95, 3964.84, 4385.55, 4465.07, 4575.17, 4637.15, 4686.45, 
4811.95, 4935.6, 5070.89, 5166.64, 5184.18, 5540.48, 5343.45, 
371.34, 427.29, 464.19, 521.51, 583.99, 703.72, 840.17, 945.7, 
1008.5, 1043.32, 1075.79, 1146.37, 1200.79, 1277.23, 1393.9, 
1532.03, 1653.41, 1747.22, 1800.6, 1833.71, 1855, 1854.8, 1882.94, 
1947.81, 2091.74, 2268.94, 2481.86, 2624.9, 2711.99, 2751.55, 
2900.07, 2991.66, 3178.81, 3341.01, 3438.72, 3564.07, 3663.65, 
3733.93, 3723.32, 3787.74, 3871.96, 3967.37, 4043.52, 4136.49, 
4306.92, 4801.53, 5083.86, 281.7, 393.11, 444.82, 492.42, 538.34, 
590.83, 628.88, 908.05, 963.37, 982.67, 1019.67, 1127.93, 1142.33, 
1253.68, 1334.71, 1382.16, 1580.57, 1632.18, 1915.11, 2407.36, 
2258.1, 2153.88, 2187.45, 2380.77, 2547.98, 2755.14, 3213.64, 
3366.84, 3356.29, 3601.41, 3844.92, 4313.06, 4503.21, 4858.75, 
5521.38, 5745.98, 6010.87, 6197.59, 6443.51, 6529.87, 6967.44, 
8480.61, 9325.13, 8664.89, 8495.86, 9322.57, 8978.91, 355.89, 
427.6, 525.96, 619.82, 610.04, 631.38, 748.69, 1034.42, 1137.97, 
1184.06, 1325.52, 1668.05, 1916.6, 2636.14, 3050.94, 3188, 3513.43, 
3429.32, 3446.57, 3292.77, 3321.66, 2979.39, 3152.31, 3457.57, 
4104.62, 3758.43, 4180.85, 4585.45, 4490.68, 4875.03, 5006.24, 
5254.51, 5867.96, 6343.1, 6718.48, 7365.17, 8085.91, 8386.79, 
9403.26, 10093.24, 10667.29, 11775.22, 11238.25, 11823.46, 12068.37, 
12587.76, 13975.46, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 4303.64, 
4957.45, 5190.77, 5907.38, 8040.08, 8170.02, 7388.67, 8273.89, 
8772.8, 8599.52, 9145.4, 9436.84, 9985.63, 10544.22, 11072.15, 
11685.66, 12217.59, 12569.16, 13693.8, 14528.2, 15725.21, 16300.3, 
18114.16, 376.32, 431.98, 467.93, 512.01, 565.94, 644.24, 751.63, 
875.99, 966.24, 1024.87, 1091.35, 1168.63, 1241.06, 1336.46, 
1441.96, 1536.1, 1652.23, 1707.42, 1693.99, 1687.33, 1675.21, 
1669.98, 1710.37, 1803.16, 1922.23, 2074.98, 2209.45, 2341.71, 
2503.4, 2641.83, 2803.29, 2965.07, 3203.39, 3352.63, 3527.69, 
3701.48, 3808.3, 3922.67, 3993.35, 4058.53, 4206.86, 4261.68, 
4361.14, 4475.34, 4599.53, 5175.58, 5260.56)), row.names = c(NA, 
-658L), class = "data.frame")

CodePudding user response:

highlighted plot

CodePudding user response:

I got it figured out using the color=variable from Stefan, and I changed from size to lwd and moved it outside of the aes()

main.plot.right.bottomv2<-ggplot() 
  # geom_line(lwd=c(rep(1,9),2,rep(1,4))) 
  geom_line(data=TabB42_melt, 
            aes(x=Year, y=value, group=variable, color=variable)) 
  #scale_size_manual(values=c(rep(1,10),3,rep(1,3))) 
  scale_color_manual(values=col.pal_wB) 
  geom_line(data=subset(TabB42_melt,variable=="Average",drop.levels=T), 
            aes(x=Year, y=value, color=variable),lwd=1.5) 
  ylab("per capita health care spending (CDN)") 
  ggtitle("Per capita spending is increasing over the years") 
  labs(colour="Province") 
  guides(size=FALSE) 
  theme_bw() 
  theme(axis.text = element_text(size = 12),
        axis.title = element_text(size = 12),
        legend.text=element_text(size=10),strip.text = element_text(size = 10),
        legend.title = element_blank(), legend.justification="left",
        legend.margin=margin(0,0,0,0),
        legend.box.margin=margin(-5,-5,-5,-5))

enter image description here

  • Related