0

I am plotting with r, but the legend is too big. when I reduce the cex, the text shrinks but the legend box still has huge empty spaces. the legend code is:

legend('topleft',adj = c(0, 0.6), pch=c(4,1), c("non smokers", "smokers"), cex=.75,horiz = TRUE,pt.cex = 1)

how can I fix this?thx

enter image description here

Cina
  • 9,759
  • 4
  • 20
  • 36
  • @d.b, it is 800x800, but doesn't work! no matter what size I select, still is too big. – Cina Sep 08 '17 at 00:37
  • @Cina Please help us by giving us a [Reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Use `dput` to provide the data for the plot and the code that you used to create the plot - not just the legend. – G5W Sep 08 '17 at 01:15
  • You can probably get some help by including `bty="n" ` in your legend statement – G5W Sep 08 '17 at 01:19

1 Answers1

1

First specify the plot size using windows or pdf or png and it will be fine. Here's an example using png

graphics.off()
png(filename = "test.png", width = 7, height = 7, units = "in", res = 75)
plot(1:10, 1:10)
legend('topleft', pch=c(4,1), c("non smokers", "smokers"), horiz = TRUE)
dev.off()

enter image description here

d.b
  • 32,245
  • 6
  • 36
  • 77
  • it works in this way. but, I am plotting in rstudio, using it for viewing the plot. In this way, the legend size is still big. Can I fix it by giving any parameter to the legend? – Cina Sep 08 '17 at 01:24