Search code examples
julialabelbar-chartfrequency

Add values on top of bars in barplot Julia


I have the following barplot in Julia Plots:

using DataFrames
using Plots

df = DataFrame(group = ["A", "B"], 
               value = [10, 9])

bar(df[!, "group"], df[!, "value"], legend = :none)

Output:

enter image description here

I would like to show the values of each bar on top of each bar. So in this example, it should show the values 10 for bar A and 9 for bar B. Is there an automatic way for this or should you annotate the values in Julia Plots?


Solution

  • An approach using annotate.

    julia> using DataFrames
    julia> using Plots
    
    julia> bar(df.group, df.value, legend = :none)
    
    julia> annotate!(df.group, df.value, df.value, :bottom)
    

    bar plot with text annotation above bars