Я создал этот график с помощью ggplot2:
Внешние линии должны соответствовать шкале Y (т.е. позиция Y строк для Text1 должна быть 100 и 85). Единственный способ, которым я могу это сделать, нарисовать пустой рисунок справа от фигуры с тем же масштабом, что и баррикад, а затем использовать функцию аннотации для рисования линий. Другой подход состоит в том, чтобы просто "вручную" рисовать линии с помощью grid.lines
, однако координаты grid.lines
не будут соответствовать шкале Y графика.
Можно ли каким-то образом провести эти строки с использованием другого подхода? Я предполагаю, что это нужно сделать с помощью grid.lines
. Как я могу передать координаты Y на барчате на 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"))
Как рисовать строки справа от столбцов?
Недавно я задал вопрос о рисовании текста вне области графика в ggplot2, и решение должно было использовать gt$layout
и grid.draw
.
Отображение текста под графиком, созданным ggplot2
Можно ли использовать такой подход? Я понимаю, что annotation_custom используется только для текста и не будет работать с другими графическими элементами. Благодаря