using StatsBase, # for the countmap function
Plots # to plot
gr() # setup plotting backend, GR is default.
# There is also PyPlot, PlotlyJS, and PGFPlots.
a=rand('a':'f',50) # create a random distribution of letters a through f to serve as the dataset
dc = countmap(a) # convert dataset to a Dict
bar(
string.(collect(keys(dc))), # the x-axis - the keys of the dictionary collected into an Array converted to Strings
collect(values(dc)), # the y-axis - frequency.
xlabel = "Letter", # the label on the x-axis
ylabel = "Frequency",# the label on the y-axis
title = "Frequency per letter"
)
I like Gadfly for plotting. It’s little easier with DataFrames, but arrays work as well.
using Gadfly
using StatsBase
a=rand(‘a’:‘f’,100)
m=countmap(a)
d=hcat(collect(keys(m)),collect(values(m))) # create a 2x100 array with the results of countmap
d=sortslices(d,dims=1,by=x->x[1]) # sort the whole array by character in column 1
plot(d,x=convert.(Int,d[:,1]),y=d[:,2],Scale.x_discrete(labels=x->Char(x)),Geom.bar(position=:dodge), Guide.xlabel(“Character”),Guide.ylabel(“Count”),Theme(bar_spacing=1cm))
It is not entirely clear though whether this starts with the kind of data structure you were asking for? Here we start with a Vector{Char}, not a Vector{String}, which you were asking about?