![](/img/trans.png)
[英]Error 43 while knitting a r markdown to pdf on rStudio on Windows
[英]Knitting R markdown (with plot() function) to PDF gives error
在将 RMD 编织到 PDF 时,出现以下错误:
Quitting from lines 47-76 (ABC.Rmd)
Error in (function (file = if (onefile) "Rplots.pdf" else "Rplot%03d.pdf", :
cannot open file '~/Read and visualize the "governorate" shapefile-1.pdf'
如果我尝试查看它是否适用于 HTML,则会收到以下错误:
Quitting from lines 47-76 (ABC.Rmd)
Error in png(..., res = dpi, units = "in") : unable to start png() device
Calls: <Anonymous> ... in_dir -> plot2dev -> do.call -> <Anonymous> -> png
In addition: Warning messages:
1: In png(..., res = dpi, units = "in") :
unable to open file '~/Read and visualize the "governorate" shapefile-1.png' for writing
2: In png(..., res = dpi, units = "in") : opening device failed
现在我不知道它是否与 plot function 有关,因为我从来没有用“ggplot”得到这个错误
```{r Read and visualize the "governorate" shapefile, echo = FALSE}
# Import the Iraqi regions shapefile
Iraq_Regions = readOGR(dsn = "~/governorates.shp")
# Import the Baghdad neighborhood shapefile
Baghdad_Neigh = readOGR(dsn = "~/baghdad_neighborhoods.shp")
# Plot the Wiki Leaks data frame
plot(x=Wiki_Leaks$Longitude, y=Wiki_Leaks$Latitude, pch=20, col='red', cex=0.4)
plot(Iraq_Regions, border='blue', add=T)
plot(Baghdad_Neigh, border='yellow', add=T)
# Merge neighborhoods to make the Baghdad city outline
Greater_Baghdad <- gUnaryUnion(Baghdad_Neigh)
# Plot the shapefiles
plot(x=Wiki_Leaks$Longitude, y=Wiki_Leaks$Latitude, pch=20, col='red', cex=0.4)
plot(Iraq_Regions, border='blue', add=T)
plot(Greater_Baghdad, border='yellow', add=T)
# view the names of different regions and the numbers of records in each region
#table(Wiki_Leaks$Region)
# Retrieve all events near Baghdad
Wiki_Leaks_MND_N_df = Wiki_Leaks[Wiki_Leaks$Region == "MND-N", ]
# Now make a basic plot
plot(x = Wiki_Leaks_MND_N_df$Long, y = Wiki_Leaks_MND_N_df$Lat,
pch = 20, col = 'red', cex = 0.4,
ylab = "Longitude", xlab = "Latitude",
main = "Death Events in Baghdad Neihborhood MND-N")
```
您需要在命名代码块时删除标点符号,这将用于命名您的文件( 例如,此处有更多信息)。
在您的情况下,删除"governorate"
将解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.