我想在ggplot2图表中添加箭头。我不断收到错误:' grob'路径必须包含至少一个名称' grob'。
library(ggplot2)
library(grid)
#create a plot
grid.newpage()
update_geom_defaults("smooth", aes(color="black"))
print(
ggplot(mtcars, aes(x=disp, y=mpg)) +
geom_point() +
geom_smooth(method=lm)
)
#list views
current.vpTree()
# change the view
downViewport("panel.6-4-6-4")
# add an arrow
sline <- grid.get(gPath("smooth", "polyline"),
grep=TRUE)
grid.segments(.7, .8,
grobX(sline, 45), grobY(sline, 45),
arrow=arrow(angle=10, type="closed"),
gp=gpar(fill="black"))