我用ggplot2创建了这个情节:

外线需要对应Y刻度(即Text1的线的Y位置应为100和85).我可以通过在条形图右侧绘制一个空白绘图并使用与条形图相同的比例然后使用注释函数绘制线来实现此目的.另一种方法是简单地"手动"绘制线条grid.lines,但是坐标grid.lines不对应于图形的Y标度.
是否有可能以某种方式使用不同的方法绘制这些线?我认为必须完成它grid.lines.我怎么能把条形图的Y coordindates传递给grid.lines?
下面是用于创建此图的最小代码:
library (ggplot2)
test= data.frame(
group=c(rep(1,6), rep(2,6)),
subgroup=c( 1,1,1,2,2,2,1,1,1,2,2,2),
category=c( rep(1:3, 4)),
count=c( 10,80,10,5,90,5, 10,80,10,5,90,5 )
)
qplot(subgroup,
count,
data=test,
geom="bar",
stat="identity",
fill =category,
facets = .~ group, width=0.9)+
opts(legend.position="none",
plot.margin = unit(c(0,9,2,0), "lines"))
Run Code Online (Sandbox Code Playgroud)

如何画出条形图右侧的线条?
我最近在ggplot2中问了一个关于在绘图区域之外绘制文本的问题,解决方案是使用gt$layout和grid.draw.
可以在这里使用类似的方法吗?据我所知,annotation_custom仅适用于文本,不适用于其他图形元素.谢谢
我正在尝试使用gridExtra包格式化表.gridExtra我的包是2.0和R版本是3.2.1
我在stackoverflow上找到关于格式化的答案,建议的选项似乎只适用于旧版本的软件包.例如,
grid.table(data, h.even.alpha = 1, h.odd.alpha = 0,
v.even.alpha = 1, v.odd.alpha = 1,
gpar.corefill, gpar.coretext)
Run Code Online (Sandbox Code Playgroud)
所有这些选项在最新版本中显示为"未使用的参数".
进一步搜索,我发现在新的gridExtra包中,格式化可能在主题内定义,例如 -
tt <- ttheme_default(core=list(fg_params=list(hjust=1, x=0.95)),
colhead=list(fg_params=list(col="brown"))
Run Code Online (Sandbox Code Playgroud)
然后做
grid.table(data, theme=tt).
Run Code Online (Sandbox Code Playgroud)
我找不到的是如何定义主题中的这些选项以及现在可以完成旧版本中可能的所有格式化.
特别是,我希望做到 -
我想为每个方面添加自定义图像.使用annotation_custom复制所有方面的图像,例如:
require(ggplot2); require(grid); require(png); require(RCurl)
p = ggplot(iris, aes(Sepal.Length, Sepal.Width)) + geom_point() + facet_wrap(~Species)
img1 = readPNG(getURLContent('https://cdn2.iconfinder.com/data/icons/animals/48/Turtle.png'))
img2 = readPNG(getURLContent('https://cdn2.iconfinder.com/data/icons/animals/48/Elephant.png'))
img3 = readPNG(getURLContent('https://cdn2.iconfinder.com/data/icons/animals/48/Hippopotamus.png'))
a1 = annotation_custom(rasterGrob(img1, interpolate=TRUE), xmin=7, xmax=8, ymin=3.75, ymax=4.5)
a2 = annotation_custom(rasterGrob(img2, interpolate=TRUE), xmin=7, xmax=8, ymin=3.75, ymax=4.5)
a3 = annotation_custom(rasterGrob(img3, interpolate=TRUE), xmin=7, xmax=8, ymin=3.75, ymax=4.5)
p + a1
Run Code Online (Sandbox Code Playgroud)
是否有另一种方法可以实现这一点,从而img1-3正确填充各个方面?