问题
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