我是這個論壇的新手,一般對R來說是新手。 但最近我被介紹給Rstudio的rmarkdowns,我一直在準備一個腳本,它使用一些csv文件來運行一些計算,然後創建一些圖。在製圖時出現rmarkdown錯誤
以股代息如下(附數據):SE_MACover_Abr2014_40m_CP.csv
```{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"))
df$Imgs <- factor(df$Imgs, levels = c("2", "5","10", "20","30", "40", "50", "60", "70"))
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
我在R基本嘗試這樣做,工作得很好,但在rmarkdown的Rstudio地塊不積,它給了我下面的錯誤信息:
錯誤(功能(文件名= 「Rplot%03d.png」,寬度= 480,高度= 480,:無效 '文件名'
看回溯它顯示以下內容:
- stop(「invalid'filename'」)
- (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」))...
- do.call
- .rs.createNotebookGraphicsDevice(filename,height,width,單位,pixelRatio,extraArgs)
- (function(){.rs.createNotebookGraphicsDevice(filename,height,width,units,pixelRatio,extraArgs)...
- grid.newpage()
- print.ggplot(X)
- 功能(X,...)UseMethod( 「打印」)(X)
我甚至tryied與繪製簡單的圖表驗證碼:
x <- c(1,2,3,4,5,6)
y <- c(1,2,3,4,5,6)
plot(x,y)
當我努力工作了這一點,因爲我覺得有我的劇本有問題, 有人建議在一段腳本粘貼密謀直接進入控制檯。 我這樣做,它的工作! 它產生於rmarkdown同樣的錯誤,但它運行在控制檯很好..
我不知道如何解決這個問題,所以我可以運行我的降價文件,它會創造我所需要的圖形,
請幫我
你是用'''關閉你的r塊嗎?在你上面的例子中,你沒有這樣做。並且第二塊名稱中的逗號也很重要,因爲RMarkdown認爲有更多的參數,用逗號分隔。 –
@J_F是對的,引用你的塊名稱,你應該沒問題。例如。 ''情節手段,分鐘和最大值''。 –
你好,謝謝你的回覆。爲了回答你的問題,我已經用'''關閉了r塊。我還引用了大塊名稱:「陰謀手段,分鐘和最大值」,並嘗試刪除昏迷。它沒有解決問題。出現相同的錯誤消息。 – anitasgiraldo