2

Have run into a problem using ggplot2 and pgfsweave(+Lyx). When I run my code in R, I get a nice plot with coloured/shaded tiles, and those tiles do not appear when running via pgfsweave. Note that other graphs using ggplot2 are working for me (using geom_line)

Is there anything I am missing?

Here is a what should be a reproducible example:

R code (which results in coloured squares):

library(ggplot2)
data(iris)

corr.Matrix <- cor(iris[1:4])

corr.Melted <- melt(corr.Matrix)
names(corr.Melted) <- c("Var1", "Var2", "Correlation")

corr.Plot <- ggplot(corr.Melted, aes(Var1, Var2, fill=Correlation)) + 
  geom_tile()

# view plot
corr.Plot

And here it is in a pgfsweave/lyx chunk (and results in a graph with no filled in squares)

\begin{center}
<<CorrelationVis,fig=TRUE,echo=FALSE>>=
  library(ggplot2)
  data(iris)

  corr.Matrix <- cor(iris[1:4])

  corr.Melted <- melt(corr.Matrix)
  names(corr.Melted) <- c("Var1", "Var2", "Correlation")

  corr.Plot <- ggplot(corr.Melted, aes(Var1, Var2, fill=Correlation)) + 
    geom_tile()

  # view plot
  print(corr.Plot)
@
\end{center}

EDIT: Adding my setup details, as it appears the example runs fine for others. - Lyx is 2.0 - pgfSweave is 1.2.1 - OS is Windows 7 - R is 2-13.1

themartinmcfly
  • 2,004
  • 2
  • 13
  • 12
  • your code works perfectly for me in Lyx 2.0 on Mac OS X. – Ramnath Jul 26 '11 at 10:03
  • @Ramnath that is good, it isolates the problem to being more about my setup/configuration. If anyone can think of any tricks to help I would be glad to know. – themartinmcfly Jul 26 '11 at 11:56
  • What happens when you print the `corr.Plot` object to a graphics file without using Sweave? – Aaron left Stack Overflow Jul 26 '11 at 14:07
  • @Aaron, I have just exported to an eps file and then included as a graphic. Things work are working perfectly via that method, but lose the dynamic nature of sweave. Is there a way to automatically compile as an image and include that. I just tried putting the image generation code into sweave but the picture doesn't always change. – themartinmcfly Jul 26 '11 at 23:57
  • 2
    See the [Sweave FAQ A.9](http://www.stat.uni-muenchen.de/~leisch/Sweave/FAQ.html#x1-11000A.9) for the recommended way to put image generation code into Sweave. – Aaron left Stack Overflow Jul 27 '11 at 16:08

0 Answers0