Dr. med. Peter Robinson
2005-Oct-24 20:32 UTC
[R] Basic: setting resolution and size of an R graphic
Dear List, I am sorry if this perhaps a too basic question, but I have not found an answer in Google or in the R help system. I am trying to use R to do a very simple analysis of some data (RT-PCR and Western analysis) with a T-test and to plot the results as a histogram with error bars. (I have pasted an example script at the bottom of this mail). In order to use this for publication, I would like to adjust the resolution and size of the final image. However, even using file types such as postscript or pdf that are vector based, I get rather bad-looking results with>pdf(file="test.pdf") >source("script at bottom of mail") >dev.off()using either pdf or postscript or jpg devices. Therefore I would like to ask the list, how to best produce a graphic from the script below that would fit into one column of a published article and have a high resolution (as eps, or failing that tiff or png)? Thanks in advance for any advice, Peter ## Western.R ## A script to display the results of quantitative Western blotting with 6 repeats each at three dosages. ## This particular script has data from stimulation of fibroblasts with M-wt. # ---------- CONVENIENCE FUNCTIONS --------------------- # ## Define a simple function to draw the error bars. makeBars <- function(x,mean,se){ segments(x,mean - se/2,x,mean+se/2) segments(x-0.1,mean - se/2,x+0.1,mean - se/2) segments(x-0.1,mean + se/2,x+0.1,mean + se/2) } ##Define a simple function to write p values writeP <- function(x,mean,se,pval) { if (pval >= 0.01) { # text(x, mean + se/2 + 0.25, sprintf('p=%.2f',pval),cex=1.5) text(x +0.05, mean + se/2 + 0.4, sprintf('*'),cex=1) } else { text(x +0.05, mean + se/2 + 0.4, sprintf('**'),cex=1) } } ## define function to draw entire group ## A,B,C refer to the x positions of the x,y,z observations drawBarsAndPValueForGroup <- function(A,B,C,x.mean,x.se,y.mean,y.se,z.mean,z.se,xy.pval,xz.pval) { makeBars(A,x.mean,x.se) makeBars(B,y.mean,y.se) makeBars(C,z.mean,z.se) writeP(B - 0.05, y.mean,y.se,xy.pval) writeP(C -0.05,z.mean,z.se,xz.pval) } ## We will make a two part graphic par(mfrow=c(1,2)) ## X: 0 ## y: 0.2 ??M ## z: 0.4 ??M yTop <- 12 ## Limit for Y axis ## --- RT-PCR MMP1 --- ## x <- c(0.8839034,0.42011158,0.65318013 , 0.88494528,1.900606, 1.2572536 ) x.mean <- mean(x) x.se <- sd(x) / sqrt(length(x)) y <- c(5.067579666,2.630677502,1.881902881,1.61994864,3.356066695 ) y.mean <- mean(y) y.se <- sd(y)/ sqrt(length(y)) z <- c(13.38923048,3.677270765,3.559984278,10.83628903,12.20110874,12.8957108) z.mean <- mean(z) z.se <- sd(z)/ sqrt(length(z)) ## -- Do t test and calculate the p values -- ## xy.t <- t.test(y,x, alternative=c("greater"),var.equal=TRUE) xy.pval <- xy.t$p.value xz.t <- t.test(z, x, alternative=c("greater"),var.equal=TRUE) xz.pval <- xz.t$p.value arr <- c(x.mean,y.mean,z.mean) mat <- matrix(arr,nrow=3,byrow=F) barplot(mat, ## The data beside=TRUE, ## juxtapose values in each column rather than stacking them ylim=c(0,yTop), ## limits for y axis xlim=c(0,3), width=1, space=c(0,0.1),##space: the amount of space (as a fraction of the average bar width) ## left before each bar. beside=TRUE, can be given ## by 2 numbers, the space between bars within a group ## and space betweens bars of different groups names=c('0.0 ??M','0.2 ??M','0.4 ??M'), ylab='Relative Change', col=c('white'), cex.names=1, cex.axis=1,##cex.axis: expansion factor for numeric axis labels. cex.lab=1) ## First for the RT-PCR group start <- 0.1 first <- start + 0.5 second <- start + 1.5 third <- start + 2.5 drawBarsAndPValueForGroup(first,second,third,x.mean,x.se,y.mean,y.se,z.mean,z.se,xy.pval,xz.pval) ## --- Western MMP1 --- ## x2 <- c(1.117373856,0.690266558,1.192359586 ) y2 <- c(3.53806369,3.895634049,6.653024511 ) z2 <- c(8.609814741,3.858564979,8.492977115) x2.mean <- mean(x2) x2.se <- sd(x2) / sqrt(length(x2)) y2.mean <- mean(y2) y2.se <- sd(y2)/ sqrt(length(y2)) z2.mean <- mean(z2) z2.se <- sd(z2)/ sqrt(length(2)) ## -- Do t test and calculate the p values -- ## xy2.t <- t.test(y2,x2, alternative=c("greater"),var.equal=TRUE) xy2.pval <- xy2.t$p.value xz2.t <- t.test(z2,x2,alternative=c("greater"),var.equal=TRUE) xz2.pval <- xz2.t$p.value arr <- c(x2.mean, y2.mean,z2.mean) mat <- matrix(arr,nrow=3,byrow=F) ## mat now has the values of each type of experiment in individual columns barplot(mat, ## The date beside=TRUE, ## juxtapose values in each column rather than stacking them ylim=c(0,yTop), ## limits for y axis xlim=c(0,4), width=1, space=c(0,0.1),##space: the amount of space (as a fraction of the average bar width) ## left before each bar. beside=TRUE, can be given ## by 2 numbers, the space between bars within a group ## and space betweens bars of different groups names=c('0.0 ??M','0.2 ??M','0.4 ??M'), ylab='Relative Change', col=c('white'), cex.names=0.8, cex.axis=1, ##cex.axis: expansion factor for numeric axis labels. cex.lab=1) first <- 0.6 second <- first + 1 third <- first + 2 drawBarsAndPValueForGroup(first,second,third,x2.mean,x2.se,y2.mean,y2.se,z2.mean,z2.se,xy2.pval,xz2.pval)
Marc Schwartz (via MN)
2005-Oct-24 20:53 UTC
[R] Basic: setting resolution and size of an R graphic
On Mon, 2005-10-24 at 22:32 +0200, Dr. med. Peter Robinson wrote:> Dear List, > > I am sorry if this perhaps a too basic question, but I have not found an > answer in Google or in the R help system. I am trying to use R to do a > very simple analysis of some data (RT-PCR and Western analysis) with a > T-test and > to plot the results as a histogram with error bars. (I have pasted an > example script at the bottom of this mail). > In order to use this for publication, I would like to adjust the > resolution and size of the final image. However, even using file types > such as postscript or pdf that are vector based, I get rather bad-looking > results with > >pdf(file="test.pdf") > >source("script at bottom of mail") > >dev.off() > > using either pdf or postscript or jpg devices. > > > Therefore I would like to ask the list, how to best produce a graphic from > the script below that would fit into one column of a published article and > have a high resolution (as eps, or failing that tiff or png)? > Thanks in advance for any advice, > > Peter<Snip of code> What OS are you on? Running your example on FC4, I get the attached output for a pdf(). I suspect that on your OS, the height and width arguments are not appropriate by default. Thus, you may need to adjust your pdf (or postscript) function call to explicitly specify larger height and width arguments. Also note that to generate an EPS file, pay attention to the details section of ?postscript, taking note of the 'onefile', 'horizontal' and 'paper' arguments and settings. Also, check with your journal to see if they specify dimensions for such graphics so that you can abide by their specs if provided. If they are using LaTeX, there are means of specifying and/or adjusting the height and/or width specs in the code based upon proportions of various measures (ie. \includegraphics[width=0.9\textwidth]{GraphicsFile.eps} ). HTH, Marc Schwartz -------------- next part -------------- A non-text attachment was scrubbed... Name: test.pdf Type: application/pdf Size: 5321 bytes Desc: not available Url : https://stat.ethz.ch/pipermail/r-help/attachments/20051024/fbf70820/test.pdf