Skip to content

box doesn't surround words in legend in printed output

5 messages · Paul Johnson, Brian Ripley, Peter Dalgaard

#
I have made a plot with a legend and on the screen it looks fine, but
when I save as jpg or pdf, or print, the legend box is too small, it
cuts through the words on the right side.

I put an example here:
http://lark.cc.ukans.edu/~pauljohn/R/apdftest.pdf

Is there a work around?
#
On Wed, 8 Aug 2001, Paul Johnson wrote:

            
You need to tell us a lot more, like which OS, exactly how you saved
or printed, etc.

My guess though is that you copied from device to device.  Don't,
use plot directly on the device you wanted.  Copying plots does not
recalculate boxes for changed point sizes, for example.

If you really need to do this you will need to play with the pointsize on
the receiving device.
#
Paul Johnson <pauljohn at ukans.edu> writes:
Sort of. The key is that "replaying" graphics is not smart enough when
a graph is resized, and this effectively happens when you copy a graph
between devices. If your screen image has different (formal)
dimensions and pointsize, the stringwidths used for sizing the legend
box are not recalculated. You can either generate your plots directly
to the target device, or adjust your screen image size to fit the
target using the options to x11()/windows().
#
Prof Brian Ripley wrote:

            
I thought you knew me:)  I have: Linux, RH 7.1, R version 1.3 installed
from the RPM on R's homepage.
Yes, you are correct.  I was using dev.copy().  I notice now dev.print()
gives a better result, I should have remembered.

Perhaps one of you will tell me if there is a standard recommended way
to do this. I will eagerly follow any advice you have.  I'll even
document it(http://lark.cc.ukans.edu/~pauljohn/R/statsRus.html#5.2).  

Here is the goal:
I have hundreds of datasets, DataCulture0, DataCulture1, etc, and I
cycle through them to try to find the one that has the pattern I'm
looking for. This does it:

run<-0
updateDataSet <- function(run)
  {
    aChar<-character(1)
    aChar<-as.character(run)
    dsname<-c(paste("DataCulture",aChar,sep=""))
    data<-read.table(dsname,header=T,as.is = TRUE)
}

buildGraph <-function(data)
{
tmp1<-plot(data$acquaint~data$T,type='l', ylim=c(0,1),ylab="average
proportion",xlab="PERIOD",lty=1,pch=1,main="")
par("new"=TRUE)
tmp2<-plot(data$harmony~data$T,type='l', ylim=c(0,1),ylab="average
proportion",xlab="PERIOD",lty=2,pch=1,main="")
par("new"=TRUE)
tmp3<-plot(data$identical~data$T,type='l', ylim=c(0,1),ylab="average
proportion",xlab="PERIOD",lty=3,pch=1,main="")
par("new"=TRUE)
tmp4<-plot(data$totalEntropy~data$T,type='l',ylim=c(0,1),ylab="",xlab="",lty=4,pch=1,main="",
cex=10)

legend(max(data$T)/2,0.2,c("Acquaintance","Harmonious","Identical","Entropy"),lty=1:4,xjust=1,yjust=1)
#if you want to interact, do this:
#legend(locator(1),c("Acquaintance","Harmonious","Identical","Entropy"),lty=1:3)
}

new<-function()
{
  dsname<-updateDataSet(run)
  buildGraph(dsname)
  run <<- run+1
}

new()

Each time I type 
new()
it opens the next dataset and makes me a plot that I see on the screen.
When I see the one I want, then I need to save it. 

Perhaps I should make a function that turns on the pdf device, then
replots the figure, then turns the device off.
#
Paul E Johnson <pauljohn at ukans.edu> writes:
That'll be effective, but would it not work to use

dev.copy(pdf, file="foo", height=7, width=7)

or conversely start the whole enchillada with

x11(height=6, width=6)

??