简体   繁体   English

获取结果表以在 R 中绘制图形

[英]Obtain resulting table to plot graphics in R

I'm new with R in QGIS, I could write a simple script, and I want to obtain the table resulting, the table which R uses to create the plot graphics.我是 QGIS 中的 R 新手,我可以编写一个简单的脚本,我想获得结果表,即 R 用于创建绘图图形的表。

How can I do that?我怎样才能做到这一点?

This is the script:这是脚本:

##Point pattern analysis=group
##Layer=vector
##Titulo=string
##showplots
library("maptools")
library("spatstat")    
K <- Kest(as.ppp(Layer))
plot(K, main=Titulo)

Can anyone help me?谁能帮我?

The QGIS processing module runs each R script in a separate R session. QGIS 处理模块在单独的 R 会话中运行每个 R 脚本。 If you want to save anything created then you need to save it to a file in your script, for example:如果要保存创建的任何内容,则需要将其保存到脚本中的文件中,例如:

 save(K,file="K.RData")

Then in another R session you can do:然后在另一个 R 会话中,您可以执行以下操作:

 load("K.RData")
 library(spatstat)

and now K is restored.现在K恢复了。

You might want to pass the save file name as another parameter to your processing script, or you may want to not do this further work in QGIS...您可能希望将保存文件名作为另一个参数传递给您的处理脚本,或者您可能不想在 QGIS 中做进一步的工作......

If you want to save this as a DBF file then there's a problem caused by the fact that K is a special kind of data frame - use write.dbf(as.data.frame(K),"/path/to/K.dbf") to convert it to a plain data frame for writing.如果您想将其保存为 DBF 文件,那么 K 是一种特殊类型的数据框会导致问题 - 使用write.dbf(as.data.frame(K),"/path/to/K.dbf")将其转换为纯数据帧以进行写入。 This will lose some of the information such as labels and names of the various components but you can't store irregular data in a DBF.这将丢失一些信息,例如各种组件的标签和名称,但您不能在 DBF 中存储不规则数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM