1

I'm trying to plot using Knitr in Lyx. When I run

<<>>=
install.packages("ggplot2")
library(ggplot2)
qplot(y=y, x=1:1000, main = 'Log-Likelihood')
@

I get the error

LaTeX Error: File `figure/unnamed-chunk-6.eps.bb' not found.

I've tried including extensions in the starting brackets, but with no success. How do I get my plot?


Following the first answer, tried this:

Defining function (not that important, just to show how I get y)

<<>>=
exp.loglik <- function(lambda, obs){   
    xbar = mean(obs)   
    return(length(obs)*log(lambda)-lambda*xbar) 
}
@

Defining y (not that important, but just including to show how y is defined)

<<>>=
y = rep(NA,1000) 
for (i in 1:1000){   
    y[i] = exp.loglik(lambda=i/10000, obs=diet_data$survtime)   
}
@

Code that runs and then the error occurs (note that I installed the package in pure R as instructed)

<<warning=FALSE, message=FALSE, echo=FALSE>>=
library(ggplot2)
qplot(y=y, x=1:1000, main = 'Log-Likelihood')
@

Same ERROR: LaTeX Error: File `figure/unnamed-chunk-6.eps.bb' not found.

MichaelChirico
  • 33,841
  • 14
  • 113
  • 198
goldisfine
  • 4,742
  • 11
  • 59
  • 83

1 Answers1

1

First, install packages separately, just running install.packages in pure R. Second, you do not define y.

Here's a minimal example that produces a plot without showing R code, warnings or messages:

<<warning=FALSE, message=FALSE, echo=FALSE>>= 
library(ggplot2) 
qplot(y=10:1, x=1:10, main = 'Log-Likelihood') 
@

Edit:

I am running the following code:

<<>>= 
exp.loglik <- function(lambda, obs) {        
  xbar = mean(obs)        
  return(length(obs)*log(lambda)-lambda*xbar)  
}
@

<<>>= 
y = rep(NA,5)  
for (i in 1:5) {        
  y[i] = exp.loglik(lambda=i/5, obs=runif(5))    
} 
@

<<warning=FALSE, message=FALSE>>= 
library(ggplot2) 
qplot(y=y, x=1:5, main = 'Log-Likelihood') 
@

and I get a picture. Is your code working in clean R? Just re-run it to make sure it is. If everything is ok there, then it might be something with the LATEX/knitr installation.

tonytonov
  • 25,060
  • 16
  • 82
  • 98
  • Did not work, unfortunately. I'm still getting this error: "LaTeX Error: File `figure/unnamed-chunk-6.eps.bb' not found." – goldisfine Feb 18 '14 at 19:58