Lattice and LatticeExtra when used for producing 2 plots(Simulated and Real) on the same pane result in the following error message:
Error in UseMethod("as.layer") :
no applicable method for 'as.layer' applied to an object of class "NULL"
The R code run in RStudio is as follows:
#converting my_df.txt to a data frame called my_df by importing the dataset using RStudio's import Dataset #feature. It's attached as a PDF file called my_df.pdf. Please see the line below.
##The simulated plot
plot.Simulation <- xyplot(CV~Times,
data= subset(my_df, Times > 0.01),
type="l", # 'l' for "loess fit"
main= "Simulated vs Actual CVs",
xlab = "Time (hour)",
ylab = "Concentration (mg/mL)",
scales = list(y=list(limits=c(0,12))))
plot.Simulation # to display the simulated plot
#The real plot
MyData <- read.csv("OTC.IM.Plasma.20.txt", sep = "\t", skip = 5)
X = MyData$Time
Y = MyData$CV
plot.RealData <- plot(X, Y, type = c("p"), col = 'blue', main = "Actual Data", xlab = c('Time (hours)'), ylab = c('CV (mg/mL)'))
#Layer Simulated with Real Data plot:
plot.Simulation + as.layer(plot.RealData) # This results in the error noted at the very top.