| To: | s-news@wubios.wustl.edu |
|---|---|
| Subject: | SUMMARY: irregular appearance of different line types |
| From: | Jean V Adams <jvadams@usgs.gov> |
| Date: | Fri, 7 Oct 2005 10:17:32 -0400 |
| Sensitivity: |
|
I posted a message to this group on 30 Aug 05 regarding problems I was having creating publication-quality line graphs using thick lines (lwd>1) and different line types in S-PLUS (original message pasted below). Thanks to Patrick Burns, Tony Aldridge, Brian Ripley, Stephen Smith, Greg, and Ricardo for their helpful responses (highlights of which are also pasted below). I continued to experiment, and couldn't get anything to work satisfactorily. I wrote to Insightful support, and learned of a workaround from Kristina Kollen. Thanks, Kristina! If you're using Word 2000, the solution is pretty straightforward, but if, like me, you're using Word 2003, the workaround is a bit more cumbersome. # My example graph # wmf.graph(file="C:\\lineplot1.wmf", width=10, height=7.5) par(mar=c(5, 5, 1, 1)) plot(0:1, 0:1, type="n", xlab="X Label", ylab="Y Label", cex=1.5) for(i in 1:9) { x <- c(1, 1, 1, 4, 4, 4, 7, 7, 7)[i]/10 y <- c(3, 6, 9, 3, 6, 9, 3, 6, 9)[i]/10 lines(c(x, x+0.2, x, x+0.2), c(y, y, y-0.2, y-0.2), lty=i, lwd=3) } dev.off() Word 2000: (1) Create your graph in S-PLUS using wmf.graph(). (2) Bring the *.wmf file into Word (insert picture from file). Note that I have not tested this workaround, because I don't have Word 2000. Word 2003: (1) Create your graph in S-PLUS using wmf.graph(). (2) Bring the *.wmf file into PowerPoint (insert picture from file). (3) Ungroup the picture (convert to MSOffice drawing object). (4) Fix changes to axis and tick labels ("ungrouping" rotates them). (5) Save as *.emf file. (6) Bring the *.emf file into Word (insert picture from file). The PowerPoint steps are required because of a known bug in Word 2003 that fails to distinguish between different line types with lwd>1 in *.wmf files (they all look like solid lines). Kristina suggested that in order to avoid making changes in PowerPoint, you can modify the graph by rotating the y-axis labels and the tick labels. For example, either of the following graphs will require no editing (step 4) in PowerPoint: wmf.graph(file="C:\\lineplot2.wmf", width=10, height=7.5) par(mar=c(5, 5, 1, 1)) plot(0:1, 0:1, type="n", xlab="X Label", ylab="", cex=1.5, yaxt="n") mtext("Y Label", side=2, cex=1.5, line=2.6, at=0.5, srt=-90) axis(2, cex=1.5, at=seq(0,1,by=0.2), srt=-90) for(i in 1:9) { x <- c(1, 1, 1, 4, 4, 4, 7, 7, 7)[i]/10 y <- c(3, 6, 9, 3, 6, 9, 3, 6, 9)[i]/10 lines(c(x, x+0.2, x, x+0.2), c(y, y, y-0.2, y-0.2), lty=i, lwd=3) } dev.off() wmf.graph(file="C:\\lineplot3.wmf", width=10, height=7.5) par(mar=c(5, 5, 1, 1)) plot(0:1, 0:1, type="n", xlab="X Label", ylab="", cex=1.5, yaxt="n") mtext("Y Label", side=2, cex=1.5, line=2.6, at=0.5, srt=-90) axis(2, cex=1.5, las=1) #HORIZONTAL Y-AXIS TICK LABELS for(i in 1:9) { x <- c(1, 1, 1, 4, 4, 4, 7, 7, 7)[i]/10 y <- c(3, 6, 9, 3, 6, 9, 3, 6, 9)[i]/10 lines(c(x, x+0.2, x, x+0.2), c(y, y, y-0.2, y-0.2), lty=i, lwd=3) } dev.off() Thanks again for all the help. I've learned a lot, and while I hope that a workaround will not be necessary in the future, I'm happy to have finally found a way to create nice looking graphs in S-PLUS for use in Word. JVA `·.,, ><(((º> `·.,, ><(((º> `·.,, ><(((º> Jean V. Adams Statistician U.S. Geological Survey Great Lakes Science Center c/o Marquette Biological Station 1924 Industrial Parkway Marquette, MI 49855 USA phone: 906-226-1212 FAX: 906-226-3632 web site: www.glsc.usgs.gov e-mail: jvadams@usgs.gov ----- responses to posting ----- >>> Patrick Burns asked if I had the same problem in R. JVA> Copying a graph from the R window (as a metafile) and pasting it into a Word 2003 document worked pretty well, although some of the lines that were supposed to be straight appeared to wander a bit (especially line type 3). I also tried creating a windows metafile using the function win.metafile(), and inserting it into Word 2003, and had the same results. >>> Tony Aldridge reported on his experimentation with WordPerfect: Since your posting I tried Wordperfect (v11) and ok, but nowhere as sharp as the pdf printed. I selected the graphic from Adobe Reader (V7) then pasted into document. I even sneaked the pdf into Adobe Photoshop Elements (V3) and exported as TIF. No luck that way either. Best result for me is the cut and paste from the graphsheet window direct from Splus (v7) into Wordperfect. Printed result is better than appears on my screen. Line thickness does increase but the line styles are different between the pdf and usual graphsheet. >>> Brian Ripley suggested that the problem might be Word, or a printer/printer driver issue: I think the problem may be Word. I don't see any problem with output from postscript(), and it is hard to see how PostScript files could have this effect: they just say stroke a line from A to B with this line type. (You will not see the effect in my books either, which use postscript(). Under Unix, but I have been told (and believe) that current Windows S-PLUS uses the same postscript() device as Unix did/does.) It is not clear to me how you are producing the output, i.e. which printer driver on what printer? This could be a printer/printer driver issue. Again, I have never seen it using postscript or PDF printers. As a cross-check I looked at R's win.metafile device. That is using standard GDI calls and seems to me to also be nasty (but not as bad as a graphsheet). So I suspect it is a Windows GDI problem, and anything which goes via Windows metafiles will show the effect. JVA> Yes, Word apparently is the problem, specifically Word 2003. I tried the different printers available to me (there aren't many) and didn't find any differences. >>> Stephen Smith suggested trying png files: Like Brian Ripley, I tend to use postscript or pdf graphic files when preparing papers (via LaTeX) and find the quality is usually excellent. When I have to use Word, I stick to png files as they seem to provide quality graphs for MS Word. JVA> I played around with png files, but found the resulting lines to be too jagged. >>> Greg suggested using the line.width.factor option in wmf.graph(): I have experimented with graphics devices on windows versions of s-plus for similar reasons, and while I don't have the s-plus solution, I have observed something interesting. The wmf.graph device has an argument line.width.factor=15. If this factor is made smaller, the line types can be seen in the output file. For example, when I [use line.width.factor=1] and insert the file into word, or view the file in the WinXP viewer, the various line types are visible. Another way to do this is to simply divide the lwd in your code by a sufficiently large factor [e.g., /10]. But these are barely visible lines, especially on the printed page. Maybe as the lwd is increased, the features that distinguish the line types merge to form what appears to be a solid line, when in fact it is probably still a sequence of dots and dashes? Printer driver and/or resolution also seems to play a role. In practical terms, only the thinnest of the lwd values can be distinguished on my printers. The best option I've found is the GSview file conversion utility. It does a good job of converting ps files to other formats (I like png format using selections png16m and 600dpi). JVA> Using the wmf.graph() function and inserting the picture into Word 2003, I can get nice solid lines of different widths, or I can get nice line types of width 1, but I have not found a way to get different line types with widths greater than 1. This is the Word 2003 bug that Kristina told me about. >>> Ricardo suggested using the snapshot tool in Acrobat Reader: I am not sure if I understood what you call import, but you could try the snapshot tool in the acrobat reader toolbar. It copies the selected area into the clipboard, then just paste into word. JVA> I tried this, and the result was a little more jagged than I'd like. ----- original message ----- I am having problems creating publication quality line graphs using different line types in S-PLUS. When using a line width > 1 and a line type other than 1, the appearance of a plotted line changes depending on the angle of the line in the plot. This is a recurring problem for me. I first posted queries for a solution to this newslist nearly eight years ago! (If you're curious, check out my 11 Jun 2003 posting at http://www.biostat.wustl.edu/archives/html/s-news/2003-06/msg00066.html.) Apparently the problem has something to do with the graphics device used. My goal is to create a publication quality line graph using different line types in S-PLUS and paste/insert the result into a Word document ... preferably with no other software needed in between. I have experimented with several different approaches (see the code pasted below). Using graphsheet() gives me irregular lines, no matter whether I'm looking at them on the screen, saving them to a file using commands within graphsheet, or exporting them to a file using the GUI. Using the postscript() device also gives me irregular lines. The wmf.graph() device ignores my use of different line types ... all the lines look like lty=1. The pdf.graph() device gives me BEAUTIFUL lines (lines I never dared dream of before), but I am unable to import the image into a Word document (I only have Adobe Reader). Ugh! I am using S-PLUS® 7.0 for Windows PROFESSIONAL DEVELOPER with operating system Microsoft Windows XP Professional. I welcome any suggestions you might have to help me achieve my goal. Thanks in advance. options(warn=-1) x <- sort(seq(0, 12, 0.1), seq(9, 11, 0.01)) # irregular lines, both on screen and when exported (as eps or wmf file, for example) graphsheet(width=6.5, height=5) plot(0, 0, xlim=c(8, 12), ylim=c(-1, 1), type="n", xlab="", ylab="") for(i in 2:8) lines(x + 0.8*i, sin(x), lty=i, lwd=i-1) # irregular lines postscript(file="lineplot.eps", print.it=F, width=6.5, height=5) plot(0, 0, xlim=c(8, 12), ylim=c(-1, 1), type="n", xlab="", ylab="") for(i in 2:8) lines(x + 0.8*i, sin(x), lty=i, lwd=i-1) dev.off() # all lines look like lty=1! wmf.graph(file="lineplot.wmf", width=6.5, height=5) plot(0, 0, xlim=c(8, 12), ylim=c(-1, 1), type="n", xlab="", ylab="") for(i in 2:8) lines(x + 0.8*i, sin(x), lty=i, lwd=i-1) dev.off() # beautiful lines, but unable to import into Word pdf.graph(file="lineplot.pdf", width=6.5, height=5) plot(0, 0, xlim=c(8, 12), ylim=c(-1, 1), type="n", xlab="", ylab="") for(i in 2:8) lines(x + 0.8*i, sin(x), lty=i, lwd=i-1) dev.off() options(warn=0) |
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | Re: Boxplot on factor ord, Richard M. Heiberger |
|---|---|
| Next by Date: | contain, Kleijn, H.J. (Huub Jan) |
| Previous by Thread: | Combine dataframes different columns, Bert Jacobs |
| Next by Thread: | contain, Kleijn, H.J. (Huub Jan) |
| Indexes: | [Date] [Thread] [Top] [All Lists] |