Manual legend labels for line graph ggplot2 in R

前端 未结 1 1407
一生所求
一生所求 2021-01-26 18:36

This seems like a fairly basic question, but I\'m relatively new to ggplot2 and I can\'t seem to figure this out. If there is something basic about the \"grammar\" that I\'m mis

相关标签:
1条回答
  • 2021-01-26 19:14

    It's recommended to use data in long format for ggplot2, so melt your data first:

    library(reshape2)
    avgTerms.m <- melt(avgTerms, id.vars = "itNum")
    

    And then assign the colours based on variable:

    ggplot(data = avgTerms.m, aes(itNum, value, colour = variable)) +
      geom_line() +
      labs(x = "Iteration Number", y = "Avg # of Tags Applied") +
      scale_colour_manual(values = cbb)
    

    0 讨论(0)
提交回复
热议问题