Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从R中的矢量图形生成自定义打印符号_R_Graphics_Plot - Fatal编程技术网

如何从R中的矢量图形生成自定义打印符号

如何从R中的矢量图形生成自定义打印符号,r,graphics,plot,R,Graphics,Plot,有没有办法在R中创建自定义点?我熟悉有很多选择的pch参数,但是如果我需要绘制例如树的轮廓呢? 例如,如果我将某个点绘制为eps。(或类似)文件,我可以在R中使用它吗?。对于复杂的对象(如树),光栅解决方案并不理想 您可以使用grImport软件包来实现这一点。我在Inkscape中绘制了一个螺旋,并将其保存为drawing.ps。按照grImport中概述的步骤,我们跟踪文件并将其作为一种多边形读取 setwd('~/R/') library(grImport) library(lattice

有没有办法在R中创建自定义点?我熟悉有很多选择的
pch
参数,但是如果我需要绘制例如树的轮廓呢? 例如,如果我将某个点绘制为eps。(或类似)文件,我可以在R中使用它吗?。对于复杂的对象(如树),光栅解决方案并不理想


您可以使用
grImport
软件包来实现这一点。我在Inkscape中绘制了一个螺旋,并将其保存为
drawing.ps
。按照grImport中概述的步骤,我们跟踪文件并将其作为一种多边形读取

setwd('~/R/')
library(grImport)
library(lattice)

PostScriptTrace("drawing.ps") # creates .xml in the working directory
spiral <- readPicture("drawing.ps.xml")

Hi@docendodiscimus!。我不认为这是一个重复的问题。我已经编辑了这个问题。希望图像能清楚地解释光栅解决方案不起作用的原因。您没有明确要求使用非
ggplot
解决方案。如果您可以考虑<代码> ggPrp>代码>,请看一看。还可以查看我和@joran评论中的建议。我认为这可以通过
grImport
包来完成,至少对于.ps文件是这样。您可以找到一些示例,查看图8。。
# generate random data
x = runif(n = 10, min = 1, max = 10)
y = runif(n = 10, min = 1, max = 10)

# lattice (as in the vignette)
x11()
xyplot(y~x,
       xlab = "x", ylab = "y",
       panel = function(x, y) {
        grid.symbols(spiral, x, y, units = "native", size = unit(10, "mm"))
        })

# base graphics
x11()
plot(x, y, pty = 's', type = 'n', xlim = c(0, 10), ylim = c(0, 10))
xx = grconvertX(x = x, from = 'user', to = 'ndc')
yy = grconvertY(y = y, from = 'user', to = 'ndc')
grid.symbols(spiral, x = xx, y = yy, size = 0.05)