Getting “npc” coordinates of ggplot2 grob

可紊 提交于 2020-03-23 08:20:08

问题


The grid package used for generating graphics in the R language uses so-called "normal parent coordinates" (npc) to position graphical objects ("grobs"). Is it possible to get the npc coordinates of a ggplot2 grob? This would be of major help for drawing lines (for connecting data points) across facets (ggplot, drawing line between points across facets contains a solution, but this is very hard to follow for beginners)

library(ggplot2)
library(grid)

# Generate some sample data
df <- data.frame(y=c(1,2,3),x=1,Set=LETTERS[1:3])

# Plot
ggplot(df,aes(x,y)) + 
  geom_point(aes(fill=Set),color="black",shape=21,size=3) + 
  facet_grid(~Set)

# It is easy to list the grobs, but I can't see their npc coordinates
grid.ls(grid.force())

来源:https://stackoverflow.com/questions/48710478/getting-npc-coordinates-of-ggplot2-grob

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!