0

I know that this was asked before, but I don't get why my approach is wrong. As illustrated in the graph, the line representing "Occupational mean college rate" is blue, but not dashed in the legend. This seems weird to me as I am following the same approach for the scale colour and the scale linetype.

enter image description here

Here my code:

over_time_both <- ggplot() + geom_smooth(data = coll_wage_ot, aes(x= acc_sum.x, y= final.x, group = 1, color="Occupational mean college rate"), method = "loess", formula = y ~ x,
                                             se=F, linetype = 2) + 
      geom_smooth(data = coll_wage_ot, aes(x= acc_sum.y, y= final.y, group = 1, color="Occupational mean wage"), method = "loess", formula = y ~ x, se=F, linetype = 1) +  
      ggtitle("") + theme(plot.title = element_text(size=12), legend.position= c(.5, .9))   +
      scale_color_manual(name = "Type of Ranking",
                         labels = c("Occupational mean college rate", "Occupational mean wage"),
                         values = c("blue", "red"))+   
      scale_linetype_manual(name = "Type of Ranking",
                            labels = c("Occupational mean college rate", "Occupational mean wage"),
                            values = c("Occupational mean college rate" = 2, "Occupational mean wage" = 1))
      
    print(over_time_both +  theme(axis.text.x=element_text(angle = 60, hjust = 1)) +
            labs(y="100 x Change in Employment Share", x = " Skill percentile"))

Many thanks in advance!

freddywit
  • 301
  • 1
  • 5
  • 1
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. – MrFlick Mar 31 '21 at 19:36
  • 3
    The issue relates to the fact that your `linetype` argument is not within the `aes` argument therefore not reflected in the legend. Perhaps you could include your data in the question using `dput(coll_wate_ot)` so that a solution could be offered. – Peter Mar 31 '21 at 19:37
  • 1
    As suggested in the duplicate, you'll only get legends for things inside the `aes()`. If you don't have `linetype=` *inside* the `aes()`, you won't get a legend and the `scale_linetype_manual` won't do anything. – MrFlick Mar 31 '21 at 19:42

0 Answers0