如何在ggplot2中以正值和負值在條形圖中設置內向條形標籤?即條形標籤應該朝向0軸。面向條形圖中帶有負值的條形圖標籤(ggplot2)的「向內」
df <- data.frame(trt = c("a", "b", "c", "d"),
outcome = c(2.3, 1.9, 0.5, -0.5))
ggplot(df, aes(trt, outcome, label = outcome)) +
geom_bar(stat = "identity",
position = "identity") +
geom_text(vjust = "inward", color = 'red')
vjust = "inward"
是obviously不是要走的方式,因爲「向內和向外是相對於圖的物理中間,而不是在0軸」。
更新:
是'geom_text(vjust = C(1, 1,1,0),nudge_y = c(-0.1,-0.1,-0.1,0.4),color ='red')'類似於你之後的東西? – hrbrmstr
@hrbrmstr:原則上是,外觀很好(呃,我寧願對所有'nudge_y'值使用( - )0.05,但這只是光學)。然而,我主要關心的是,我想製作許多這樣的圖形,而且我必須根據變量的值手動調整每個圖形。總體而言,並不完全。 – dpprdan