0

I have searched for an answear on the site and found a lot of material. It looks like those work for everyone but me. I cannot make a legend at my ggplot. I tried also scale_colour_manual option but it does not work. None of the plots have a legend. I cannot find any working solution and I hope you can help me. Tried even to restart a computer :)

Here is my code and data:

ggplot(vec_freq_bind, aes(x=vec_freq_bind[,3])) +
  geom_line(aes(y=vec_freq_bind[,2]),
            color="#69b3a2", size=2, alpha=0.9, linetype=2,show.legend = TRUE) +
  geom_line(aes(y=vec_freq_bind[,5]),
            color="#BB4444", size=2, alpha=0.9, linetype=2,show.legend = TRUE) +
  scale_color_discrete(name = "Y series", labels = c("Y2", "Y1"))

Here is the data:

vec_freq_bind[,3] [1] 10 20 30 40 50 60 70 80 90

vec_freq_bind[,2] [1] 1164 606 352 198 148 104 63 43 23

vec_freq_bind[,5] [1] 1025 598 375 249 189 106 67 38 21

tjebo
  • 21,977
  • 7
  • 58
  • 94
Karol
  • 1
  • 1
    Hi Karol. If you want to post data type `dput(vec_freq_bind)` into the console and copy and paste the output starting with `structure)...` into your post. Makes it much easier to help you. – stefan Jan 04 '21 at 17:25
  • 2
    Second. If you want to have a legend you have to map on aesthetics, i.e. move `color=...` inside `aes()` and set the color via `scale_color_manual`. See e.g. my answer https://stackoverflow.com/a/65555202/12993861 or https://stackoverflow.com/questions/48768567/reasons-that-ggplot2-legend-does-not-appear for an example on how this could be achieved. – stefan Jan 04 '21 at 17:27
  • Yes, it solved my problem. You have saved my day! I am very grateful. I am having though time converting from SAS :) – Karol Jan 04 '21 at 19:47

0 Answers0