Below code works well and it labels the barplot correctly, However, if I try geom_text
for a histogram I fail since geom_text
requires a y
-component and a histogram's y
component is not part of the original data.
Label an "ordinary" bar plot (geom_bar(stat = "identity"
) works well:
ggplot(csub, aes(x = Year, y = Anomaly10y, fill = pos)) +
geom_bar(stat = "identity", position = "identity") +
geom_text(aes(label = Anomaly10y,vjust=1.5))
My Problem: How to get the correct y
and label
(indicated by ?
) for geom_text
, to put labels on top of the histogram bars
ggplot(csub,aes(x = Anomaly10y)) +
geom_histogram()
geom_text(aes(label = ?, vjust = 1.5))
geom_text
requires x
, y
and labels
. However, y
and labels
are not in the original data, but generated by the geom_histogram
function. How can I extract the necessary data to position labels on a histogram?