Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 209949

How to get data labels for a histogram in ggplot2?

$
0
0

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 the frequency which is never a part of the code then HOW DO I bring labels for a Histogram?

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))  

Problem- no Y component(indicated by ?) in the below code for geom_text

ggplot(csub,aes(x=Anomaly10y)) + 
        geom_histogram() 
        geom_text(aes(label=?,vjust=1.5))

By Default geom requires x and y component,

What should I do when I dont have y-component as it is automatically generated by the function?


Viewing all articles
Browse latest Browse all 209949

Trending Articles