我正在尝试做的是复制此图表的一行:
它不必完全相同,但是遵循相同的想法。我也希望能画一条线。就像是:
---- Y-Y-Y-- | --N-N-N-N ----
到目前为止,我得到的最接近的是使用ggplot2theme()
来隐藏轴,但没有提出我喜欢的东西。
如果您提供了正在使用的数据的简短样本,这将使问题更容易回答。假设您有这样的事情:
votes <- data.frame(vote=paste(1:7),
how=c(rep("Y", 3), rep("N", 4)),
legislator=c(rep("L1", 7) ) )
您可以创建类似以下的图表:
ggplot(votes, aes(x=vote, y=legislator) ) +
geom_text(aes(label=how)) +
geom_hline(aes(yintercept=1.05)) +
geom_segment(x=3.5, xend=3.5, y=0.95, yend=1.05, size=1.5)
如果您想要一个空主题,请从以下类似内容开始:(来自https://gist.github.com/dsparks/3711166)
new_theme_empty <- theme_bw()
new_theme_empty$line <- element_blank()
new_theme_empty$rect <- element_blank()
new_theme_empty$strip.text <- element_blank()
new_theme_empty$axis.text <- element_blank()
new_theme_empty$plot.title <- element_blank()
new_theme_empty$axis.title <- element_blank()
new_theme_empty$plot.margin <- structure(c(0, 0, -1, -1),
unit = "lines",
valid.unit = 3L,
class = "unit")
并像这样使用它:
ggplot(votes, aes(x=vote, y=legislator) ) +
geom_text(aes(label=how)) +
geom_hline(aes(yintercept=1.05)) +
geom_segment(x=3.5, xend=3.5, y=0.95, yend=1.05, size=1.5) +
new_theme_empty
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句