0

我希望使用 gganimate 和 tweener 将一些字母变成其他字母。因此,我需要一个单词中每个字母的 x、y 坐标数据框作为 ggplot 的输入。

我不太确定如何做到这一点,但我的想法是库(grImport)可能会有所帮助。

我通过打印创建了一个单词“hello”的 Postscript 文件,然后将输出保存到 Postscript。它在这里

此代码读取 hello.ps

library(grImport)

PostScriptTrace("figures/hello.ps", "hello.xml")
hello <- readPicture("hello.xml")
grid.picture(hello)

hello 是一个 S4 类对象。

我认为 hello 的结构为单词“hello”的每个字母保存 x,y 坐标是否正确?

如果是这样,我如何提取这些坐标?

4

1 回答 1

0

作为记录,解决方案是:

# Extract x, y coordinates of path from S4 object of class Picture
# letters[i], i is the index into the word, "hello".

x <- hello@paths$text@letters[2]$path@x 
y <- hello@paths$text@letters[2]$path@y
于 2019-02-14T01:42:20.337 回答