[R] Graphs for scientific publication ?

David Winsemius dwinsemius at comcast.net
Wed Jun 3 18:48:04 CEST 2015


On Jun 3, 2015, at 3:30 AM, Jeremy Clark wrote:

> The coding I've settled on to save file without clipping is:

What exactly was "clipping". You earlier complained about "jaggies". There was no restriction of the plotted lines to the plot area in the example you earlier presented. That's what I understand "clipping" to mean.

> 
> library(gridExtra)
> gt <- ggplot_gtable(ggplot_build(q3))
> gt$layout$clip[gt$layout$name=="panel"] <- "off"
> gt4 <- arrangeGrob(gt)
> ggsave <- ggplot2::ggsave; body(ggsave) <- body(ggplot2::ggsave)[-2]
> ## from Baptiste
> ggsave("gt.pdf", plot = gt4, width = 6, height = 6)
> ggsave("gt.png", plot = gt4, width = 6, height = 6)
> 
> Part of the problem with plotmath is that as soon as paste is used the
> syntax needed is different eg. substitute and substitute(paste( do not
> accept the same syntax eg. == or "=".
> 

There's not much context for this. If you are bothered that that you need "=" inside paste and `==` outside, then you just need to spend more time understanding expression syntax.  I have found that plotmath's `paste` usually ends up obscuring a proper understanding of expression syntax. Would be annotators reach for plotmath-`paste` because they missed the part about using "*" and "~" to separate tokens.... Oh wait ... now I remember there isn't really any section in the ?plotmath page that actually says that, is there? (Sorry, Not my area of responsibility. Took me years to learn this.)

Your other complaint about plotmath not supporting line-breaks is a recognized problem. Multi-element expression vectors are one strategy to consider.  You should also look at the grid.text function if you are working in the ggplot2-world and want fine-tuned control. You are already building a grid-based structure. (And to your whine that ggplot2 is not in base-R, consider that the grid package is.) Bert Gunter's suggestion that you purchase Murrell's "R Graphics" should be remembered. It is essentially the assembly language in which ggplot2 is written.

Learn to use bquote ... You had:

rsquaredlm = NULL
rsquaredlm[[6]] <- 3 ## false value
listr2 <- list(r2 = rsquaredlm[[6]])
eq1 <- substitute(italic(R)^2 == r2, listr2)
eqstr1 <- as.character(as.expression(eq1))
q3 <- p2 +  annotate(geom = "text", x = 20, y = 30, label = eqstr1,
parse = TRUE, vjust = 1)

The results from `bquote` appear to be handled properly within ggplot2-code. (Lattice functions do not like `bquote` for its expressions, since they are not actually in expression mode.)

rsquaredlm = NULL
rsquaredlm[[6]] <- 3 
 eq1 <- bquote(italic(R)^2 == .(rsquaredlm[[6]]))  # the value will be substituted in the plot
 eqstr1 <- as.character(as.expression(eq1))
q3 <- p2 +  annotate(geom = "text", x = 20, y = 30, label = eqstr1,
parse = TRUE, vjust = 1)

-- 

David Winsemius
Alameda, CA, USA



More information about the R-help mailing list