Search code examples
rggplot2geom-text

Sorting out the geom_text() placement in ggplot


I have a a dataset with 3 columns called df

Name, value, Freq

I have constructed a graph with geom_bar() & geom_text() function

ggplot(df, aes(x=name, fill=value, y=Freq)) + geom_bar(stat = "identity") + geom_text(aes(label=Freq))

with the output:

enter image description here

How would i be able to sort out the confused text label placement?

Any help would be greatly appreciated. Thanks.


Solution

  • Try this:

    library(ggplot2)
    #Code
    ggplot(df, aes(x=name, fill=value, y=Freq)) +
      geom_bar(stat = "identity") +
      geom_text(aes(label=Freq),position = position_stack(0.9))