annotation_custom意外地表现

时间:2014-11-16 10:39:06

标签: r ggplot2

我无法在绘图中添加一些弯曲的箭头。该图结合了geom_polygon() ...

require(rworldmap)    
g <- ggplot() + geom_polygon(data = getMap(resolution = 'low'),
                        aes(x = long, y = lat, group = group)) 

...来自不同数据源的大量geom_point()个。 e.g:

data1 <- c(0, 52)
g + geom_point(aes(data1[1], data1[2]), size = 5, color = 'red')   

到目前为止,这么好。我遇到的具体问题是将curveGrob()添加为annotation_custom()。这是一条简单的曲线:

myCurve<-curveGrob(0, 0, 1, 1, default.units = "npc",
                   curvature = 0.3, angle = 90, ncp = 20, shape = 1,
                   square = FALSE, squareShape = 1,
                   inflect = FALSE, arrow = arrow(), open = TRUE,
                   debug = FALSE,
                   name = NULL, gp = gpar(), vp = NULL)

这里有一些简化的代码来证明我的问题。这个位按预期工作。

data <- data.frame(x = c(1:10), y = c(11:20))
base <- ggplot(data = data, aes(x, y)) + geom_point()
base + annotation_custom(grob = myCurve)

但是当ggplot()命令为空时(由于不同的geom使用不同的数据而需要,annotation_custom()无法绘制

base <- ggplot() + geom_point(data = data, aes(x, y))
base + annotation_custom(grob = myCurve)

0 个答案:

没有答案
相关问题