Is there some way how to make custom points in R? I am familiar with pch
argument where are many choices, but what if I need to plot for example tree silhouettes?
For example if I draw some point as eps. (or similar) file, can I use it in R?. Solution by raster is not good in the case of complicated objects (f.e. trees).
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You can do this with the grImport
package. I drew a spiral in Inkscape and saved it as drawing.ps
. Following the steps outlined in the grImport vignette, we trace the file and read it as a sort of polygon.
setwd('~/R/')
library(grImport)
library(lattice)
PostScriptTrace("drawing.ps") # creates .xml in the working directory
spiral <- readPicture("drawing.ps.xml")
The vignette uses lattice to plot the symbols. You can also use base graphics, although a conversion is needed from device to plot coordinates.
# 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)