1

When I try to add the legend to the bottom center, it overlaps with the y axis label.

Here is an image of the plot for reference:

1

And my code:

legend('center',
       'groups',
       lty=1,
       col=c("red","gold","blue","green","black","purple","orange","pink","grey","dark blue","violet","dark red","brown","maroon"),
       legend=c("Babl","Chli","Cuaz","Frve","Juma","Pafl","Pibr","Pich","Plwr","Prgl","Quvi","Sela","Ulpa","Vaca"),
       bty="n",
       xpd = TRUE,
       ncol=3)
zx8754
  • 52,746
  • 12
  • 114
  • 209
Kal N
  • 11
  • 1
  • Please add more code of your legend. As is - it's plotted at the center of the image. Maybe you are missing some additional line you called before calling `legend()`? – Karolis Koncevičius Nov 20 '21 at 18:07
  • 2
    Does this answer your question? [Plot a legend outside of the plotting area in base graphics?](https://stackoverflow.com/questions/3932038/plot-a-legend-outside-of-the-plotting-area-in-base-graphics) – Karolis Koncevičius Nov 20 '21 at 18:11
  • 1
    i'm not sure anyone actually read the question.. when you make your plot, just omit the xlab (`xlab = '')` and adjust the position after the plot `title(xlab = ..., line = 4)` until it is not overlapping with the legend. you may need to increase the margins of the plot first `par(mar = c(8, 5, 2, 1))` etc to have more space for both the legend and the xlab – rawr Nov 20 '21 at 18:40

1 Answers1

1

In your legend, you specify that you want your legend to be in the center. You can change the position by replacing "center" with "bottomright", "bottom", "bottomleft", "left", "topleft", "top", "topright", and "right".

neuron
  • 1,949
  • 1
  • 15
  • 30