Error plotting using rmarkdown

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Error plotting using rmarkdown

anitasgiraldo
Hi all,

I am new to this forum and new to R in general.
But recently I was introduced to rmarkdowns in Rstudio and I have been getting a script ready that uses some csv files to run some calculations and then creates some plots.

Scrip as follows (data attached):SE_MACover_Abr2014_40m_CP.csv


## Making the plots
```{r prepare the data}

df <- read.csv(file.choose()) #SE_MACover_Abr2014_40m_CP.csv

#   call the libraries

library(ggplot2)
library(plyr)
library(reshape2)

str(df)
df

## create factor levels
df$Stat <-factor(df$Stat, levels = c("SE_Mean", "SE_Min","SE_Max")) ## makes the columnd 'Stat' a vector
df$Imgs <- factor(df$Imgs, levels = c("2", "5","10", "20","30", "40", "50", "60", "70")) ## makes the column 'Imgs' a vector
df$Stat
df$Imgs

```{r plot means, mins, and maxs}
Plot1 <- ggplot(data = df, aes(x = Imgs, y = X, group = Stat)) +
  geom_line(aes(linetype = Stat, colour = Stat), size = 1) +
  geom_point(aes(colour=Stat)) +
  ylab(bquote('Standard Error ')) +
  xlab(bquote('Number of Images'))
Plot1


I tried this in R base and worked fine, but rmarkdown in Rstudio the plots do not plot and it gives me the following error message:

Error in (function (filename = "Rplot%03d.png", width = 480, height = 480, : invalid 'filename'

looking at the traceback it shows the following:

8.
stop("invalid 'filename'")
7.
(function (filename = "Rplot%03d.png", width = 480, height = 480, units = "px", pointsize = 12, bg = "white", res = NA, family = "sans", restoreConsole = TRUE, type = c("windows", "cairo", "cairo-png"), antialias = c("default", "none", "cleartype", "gray", "subpixel")) ...
6.
do.call(what = png, args = args)
5.
.rs.createNotebookGraphicsDevice(filename, height, width, units, pixelRatio, extraArgs)
4.
(function () { .rs.createNotebookGraphicsDevice(filename, height, width, units, pixelRatio, extraArgs) ...
3.
grid.newpage()
2.
print.ggplot(x)
1.
function (x, ...) UseMethod("print")(x)


I even tryied plotting the simplest graph with this code:
x <- c(1,2,3,4,5,6)
y <- c(1,2,3,4,5,6)
plot(x,y)

While I was trying to work this out as I thought there was a problem with my script,
someone suggested to paste the piece of script for plotting straight into the console.
I did so and it worked!
And it produces the same error in rmarkdown, but it runs fine in the console..

I don't know how to fix this so I can run my markdown file and it will create the graphs I need,

Please help me