I have a question about antialiasing when R generates bitmaps. (This follows a thread on the ggplot2 mailing list.)
I mostly use R on Linux, although I sometimes use it in Mac and Windows as well. On Linux, I've found that plotting shapes 15-18 via cairo results in bad-looking output. The points are not antialiased, and they are jagged and misshapen. Plots generated in Windows also aren't antialiased, but at least the vector shapes seem to be aligned to pixel boundaries so that the raster images look consistent. You can see this in the scatterplots I've posted here: http://stdout.org/~winston/X/r-antialias/pch.html Also on that page are pch symbol charts from a modified version of pchShow() from the pch help page. I rendered PNG's of the chart on Mac, Linux, and Windows, using png() and setting "type" to Xlib, cairo, quartz, if available on the given platform. In Windows, I did it without the type argument (in Windows, the flag wasn't available). Finally, I also installed the Cairo package and used CairoPNG. Please note the distinction between "cairo", which is built-in, and "Cairo", which is an installed package. (Side note: there's no Mac-Xlib image, but only because I had some X server issues on that computer.) Here are some observations and questions that hopefully someone can answer: - With cairo, all shapes are antialiased except 15-18. Why do cairo and Cairo give different results for shapes 15-18? - With CairoPNG, all shapes are antialiased. Title text looks different between the platforms, though. On Mac, it's normal text; on Linux, it's bold; and on Windows, it's italic. I believe that font.main was set to 2, so it should be bold. Why does Cairo render text so differently on different platforms? It would be nice not to have to tailor scripts to fit the quirks of whatever platform I happen to be at. For example, to have the title render properly in bold and have all shapes be anti-aliased, here's what I would need to do: - Mac: png(type="quartz") - Linux: CairoPNG() - Windows: not possible Ideally, I would like to use the same command on all platforms to generate good antialiased graphs with similar-looking fonts. Is such a thing possible? -Winston This is the code that I used to generate all the images for each platform: pchShow <- function(extras = c("*",".", "o","O","0","+","-","|","%","#"), cex = 3, ## good for both .Device=="postscript" and "x11" col = "red3", bg = "gold", coltext = "brown", cextext = 1.2, main = paste("plot symbols : points (... pch = *, cex =", cex,")")) { nex <- length(extras) np <- 26 + nex ipch <- 0:(np-1) k <- floor(sqrt(np)) dd <- c(-1,1)/2 rx <- dd + range(ix <- ipch %/% k) ry <- dd + range(iy <- 3 + (k-1)- ipch %% k) pch <- as.list(ipch) # list with integers & strings if(nex > 0) pch[26+ 1:nex] <- as.list(extras) plot(rx, ry, type="n", axes = FALSE, xlab = "x-axis label", ylab = "y-axis label", main = main) abline(v = ix, h = iy, col = "lightgray", lty = "dotted") for(i in 1:np) { pc <- pch[[i]] ## 'col' symbols with a 'bg'-colored interior (where available) : points(ix[i], iy[i], pch = pc, col = col, bg = bg, cex = cex) if(cextext > 0) text(ix[i] - 0.3, iy[i], pc, col = coltext, cex = cextext) } } sysname <- paste(version$platform, "_", version$major, ".", version$minor, sep="") # Make the scatterplot set.seed(123) png(paste(sysname, "-default_png_scatterplot.png", sep=""), width=300, height=300) plot(rnorm(20),rnorm(20), pch=16, main=paste(sysname,"pch=16")) dev.off() # Get the possible types on this computer (cairo, Xlib, etc) types <- NULL if (capabilities()["cairo"]) types <- c(types, "cairo") if (capabilities()["X11"]) types <- c(types, "Xlib") if (capabilities()["aqua"]) types <- c(types, "quartz") # Generate the images if (is.null(types)) { # If no types available png(paste(sysname, "-default_png.png", sep=""), width=300, height=300) pchShow(cex=.9, cextext=.8, main=paste(sysname, "default PNG output")) dev.off() } else { for (i in 1:length(types)) { # If types are available, use them png(paste(sysname, "-", types[i], ".png", sep=""), width=300, height=300, type=types[i]) pchShow(cex=.9, cextext=.8, main=paste(sysname,types[i])) dev.off() } } # Make the CairoPNG version library(Cairo) CairoPNG(paste(sysname, "-", "CairoPNG", ".png", sep=""), width=300, height=300) pchShow(cex=.8, cextext=.8, main=paste(sysname, "CairoPNG")) dev.off() [[alternative HTML version deleted]] ______________________________________________ R-help@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.