[R] Multiple palettes on single plot don't get rendered when I use dev.copy2pdf

Andrew Crane-Droesch andrewcd at gmail.com
Wed Dec 12 02:57:46 CET 2012


Thanks a lot!  This works, provided I run my version first.  For 
posterity, the following does what is wanted:

par(mfrow=c(1,1))
x1 = rnorm(1000)
x2 = rnorm(1000)+10
y1 = rnorm(1000)+10
y2 = rnorm(1000)+10
palette(rainbow(6))
plot(x=x1,y=y1,col=y1,xlim=c(-10,20))

palette(heat.colors(6))
points(x=x2,y=y2,col=y2)

     dev.copy2pdf(file = "broke.pdf", height = 8, width = 8)


  pdf("broke.pdf")
  palette(rainbow(6))
  plot(x=x1,y=y1,col=y1,xlim=c(-10,20))
  palette(heat.colors(6))
  points(x=x2,y=y2,col=y2)
  dev.off()


On 12/11/2012 04:48 PM, arun wrote:
> Hi,
> Try this:
>   pdf("broke.pdf")
>   palette(rainbow(6))
>   plot(x=x1,y=y1,col=y1,xlim=c(-10,20))
>   palette(heat.colors(6))
>   points(x=x2,y=y2,col=y2)
>   dev.off()
> A.K.
>
>
>
> ----- Original Message -----
> From: Andrew Crane-Droesch <andrewcd at gmail.com>
> To: R help <r-help at r-project.org>
> Cc:
> Sent: Tuesday, December 11, 2012 7:17 PM
> Subject: [R] Multiple palettes on single plot don't get rendered when I use dev.copy2pdf
>
> Hi All,
>
> I'm having trouble with the colors on my screen getting translated to the colors in the outputted .pdf document.
>
> Here is a caricature of my problem:
>
> par(mfrow=c(1,1))
> x1 = rnorm(1000)
> x2 = rnorm(1000)+10
> y1 = rnorm(1000)+10
> y2 = rnorm(1000)+10
> palette(rainbow(6))
> plot(x=x1,y=y1,col=y1,xlim=c(-10,20))
>
> palette(heat.colors(6))
> points(x=x2,y=y2,col=y2)
>
>      dev.copy2pdf(file = "broke.pdf", height = 8, width = 8)
>
> I plot the two normal blobs in two different color palettes, and it looks fine on the screen.  I go to look at the PDF, and they are BOTH in heat map.
>
> How would I render both palettes on the pdf?
>
> Many thanks,
> Andrew
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>




More information about the R-help mailing list