# Plot Text Data in Mathematica

I am trying to analyze some text data for my thesis! How can I plot this data in Mathematica in a barplot based on the frequency of the words and combinations of them?

On the Abscissa (x) I would have "source", "target", and the word sequence "source and target", and on the Ordinate (y) the frequencies.

{"source", "source", "and", "target", "source", "and", "target", \
"target", "source", "and", "target", "target", "source", "and", \
"target", "target", "target", "target", "target", "source", "and", \
"target", "target", "source", "and", "target", "target", "target", \
"target", "target", "source", "and", "target", "source", "and", \
"target", "target", "target", "source", "and", "target", "target", \
"target", "target", "target", "target", "target", "target", "target", \
"target", "source", "and", "target", "target", "target", "target", \
"target", "target", "source", "and", "target", "source", "and", \
"target", "source", "and", "target", "target", "target", "source", \
"and", "target", "target", "target", "target", "target", "source", \
"and", "target", "target", "source", "and", "target", "source", \
"source", "and", "target", "target", "target", "source", "and", \
"target", "source", "and", "target", "source", "and", "target", \
"target", "source", "and", "target", "target", "target", "target", \
"source", "and", "target", "source", "and", "target", "target", \
"source", "and", "target", "source", "and", "target", "target", \
"target", "source", "and", "target", "target", "source", "target", \
"target", "source", "and", "target", "source", "and", "target", \
"source", "and", "target", "source", "and", "target", "source", \
"and", "target", "source", "target", "target", "source", "and", \
"target", "target", "target", "target", "target", "source", "and", \
"target", "target", "target", "source", "source", "and", "target", \
"target", "target", "target", "source", "and", "target", "target", \
"target", "target", "target", "target", "target", "target", "target", \
"target", "source", "and", "target", "source", "and", "target", \
"target", "source", "and", "target", "source", "and", "target"}


Those are the data I want to plot! Thanks a lot in advance!

• Tally the rest is up to you Commented Oct 3, 2015 at 13:04
• @Sektor I think it is asked to find the tallies for "source", "target", and {"source","and","target"}. Regardless if that is the case or not, the question is not phrased clearly. Commented Oct 3, 2015 at 13:28
• Greetings @Ati! Make the most of Mma.SE and take the tour now. Help us to help you, write an excellent question. Edit if improvable, show due diligence, give brief context, include minimum working examples of code and data in formatted form. As you receive give back, vote and answer questions, keep the site useful, be kind, correct mistakes and share what you have learned. Commented Oct 3, 2015 at 13:29
• Ati, you should clarify what you need. Is it what Anton Antonov says? Commented Oct 3, 2015 at 13:39

I assume it is asked to find the tallies for (1) "source", (2) "target", and (3) the sequence of words "source", "and", "target".

If that is the case this code does it.

words = {"source", "source", "and", "target", "source", "and",
"target", "target", "source", "and", "target", "target", "source",
"and", "target", "target", "target", "target", "target", "source",
"and", "target", "target", "source", "and", "target", "target",
"target", "target", "target", "source", "and", "target", "source",
"and", "target", "target", "target", "source", "and", "target",
"target", "target", "target", "target", "target", "target",
"target", "target",  "target", "source", "and", "target", "target",
"target", "target", "target", "target", "source", "and", "target",
"source", "and",  "target", "source", "and", "target", "target",
"target", "source", "and", "target", "target", "target", "target",
"target", "source", "and", "target", "target", "source", "and",
"target", "source", "source", "and", "target", "target", "target",
"source", "and", "target", "source", "and", "target", "source",
"and", "target", "target", "source", "and", "target", "target",
"target", "target", "source", "and", "target", "source", "and",
"target", "target", "source", "and", "target", "source", "and",
"target", "target", "target", "source", "and", "target", "target",
"source", "target", "target", "source", "and", "target", "source",
"and", "target", "source", "and", "target", "source", "and",
"target", "source", "and", "target", "source", "target", "target",
"source", "and", "target", "target", "target", "target", "target",
"source", "and", "target", "target", "target", "source", "source",
"and", "target", "target", "target", "target", "source", "and",
"target", "target", "target", "target", "target", "target",
"target", "target", "target", "target", "source", "and", "target",
"source", "and", "target", "target", "source", "and", "target",
"source", "and", "target"};

newWords =
words //. {start___, "source", "and", "target", end___} :> {start,
"source and target", end}

BarChart[Counts[newWords], ChartLabels -> Automatic]


Update Since my answer was accepted I updated it with the commands in the answer by Szabolcs.

• Yes, awesome! This is exactly what I was asking! Sorry about the confused question!! Thank youuuuuu!!!!!!!! Commented Oct 3, 2015 at 13:42
• No problem. Good luck with the thesis! Commented Oct 3, 2015 at 14:12
BarChart[#2, ChartLabels -> #1] & @@ Transpose[Tally[data]]