0

enter image description here

My legend box is coming outside the plot, but while zooming in, the size of the legend box is very large and is not visible. Can anyone help me?

options(scipen=999)
par(mai = c(1, 2, 1, 3))
barplot(out1.1$Total,beside=TRUE,width = .65, space = .5, names.arg = out1.1$DATE,ylim=c(0,30000),yaxs='i', ylab='', col = 'green',las=1,border = 'green',cex.axis = .8,yaxt="n")
axis(2, col.tick='grey')
axis(2, tck=1, col.tick='grey')
m<-barplot(out1.1$Total,beside=TRUE,width = .65, space = .5, names.arg = out1.1$DATE,add=TRUE, ylim=c(0,30000),yaxs='i', ylab='', col = 'green',border = 'green',las=1,cex.axis = .8,yaxt="n")
title(ylab="Total Number Of calls", mgp=c(3.5,1,0),cex.lab=1.2)
box(col='grey')
par(new=TRUE)
plot(m,out1.1$Percentage_cUK,type="l",ylim=c(0,70),yaxs='i',col="orange",axes=FALSE,ann=FALSE)
lines(m,out1.1$Percentage_Dise,col="blue")
mtext('Success rate %', side = 4, col = 'orange', line = 4)
axis(1,at=seq(1, 6, by = .8),col='grey',labels = FALSE,cex.lab=0.8)
axis(4,at=seq(0,70,10),col='grey',las=1,tick = TRUE,labels = paste0(seq(0,70,10),".","00", "%"),cex.axis=0.8)
par(new = TRUE)
plot.new()
legend("bottomright",inset=c(-1.3,0.01), c("Total Entries","cUK %", "Dise %"), lty = c(2,1,1),cex=0.5)
par(new = TRUE)
plot.new()
img <- readJPEG("Capture.jpg")
plot(1:10,xaxt='n',yaxt='n',ann=FALSE,bty='n',pch='',ylab='',xlab='')
rasterImage(img,11,11,12,12)[enter image description here][1]
hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
  • Hi shivanshu, I can't run the code. Can you provide an image so it is more clear what the problem is? – StatMan Jul 27 '16 at 07:42
  • Can you provide a reproducible example (http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)? – Qaswed Jul 27 '16 at 08:00
  • Hi @MarcelG, I have added the image of my plot. The legend box is not visible as the image is zoomed in. – shivanshu dhawan Jul 27 '16 at 08:55
  • @shivanshudhawan try adding the `cex` argument to `legend()`, so e.g. `legend(..., cex = 0.75)` and then try different values for `cex` – StatMan Jul 27 '16 at 09:52
  • @MarcelG as you can see in my code, I have tried cex values. The problem is the legend is visible when I run the code but when I export the plot into an image file it disappears – shivanshu dhawan Jul 27 '16 at 11:00
  • @shivanshudhawan ah yes now I see. Try some different format, such as .png .pdf or .jpeg and see if the problem still occurs. If it still happens you can try playing around with the width (height is not relevant for you I think): `pdf(file="figure.pdf",width=xx,height=yy)` – StatMan Jul 27 '16 at 11:06
  • @MarcelG Thank you. I tried what you suggested still the legend is so large that only some of the region is visible. Didn't knew it will be this much tough – shivanshu dhawan Jul 27 '16 at 11:16
  • @shivanshudhawan also of you combine it with a very small value for the `cex` argument? – StatMan Jul 27 '16 at 11:18
  • @MarcelG Actually cex is not changing the dimensions of the legend box instead it is changing the font size of the contents in it. So the issue still remains the same – shivanshu dhawan Jul 27 '16 at 11:23

0 Answers0