-1

I'm new to R programming and I'm trying to create a frequency bar chart using base graphics. I am passing a vector called info which contains 50 items. Each item is of type character.

plot(x = info,
    main = "My title",
    xlab = "Items",
    ylab = "Count")

When I run this I get an error.

Error in plot.window(...) : need finite 'ylim' values.

I thought it might have something to do with the amount of items in the vector, so I reduced the items to 10 inside the vector called info. But the same error keeps coming up.

The character items inside the vector are anything from 20 characters in length to 60. Some of them contain commas and brackets, I'm not sure if this is an issue?

Any help greatly appreciated.

Update

Examples of the characters in the vector.

"This is some data"

"This is another example (testing)"

"This is yet, another, example (testing)"

tcode
  • 5,055
  • 19
  • 65
  • 124
  • 3
    It's difficult to provide any guidance without a [minimal and reproducible example](https://stackoverflow.com/a/5963610/5619526). You probably need to do some data summarizing before passing to `plot`, but it's hard to know without seeing your actual data – bouncyball Jan 03 '18 at 16:16
  • 1
    If `info` is of character type, try `table(info)` – LyzandeR Jan 03 '18 at 16:20
  • Unfortunately the data is sensitive, but I can show some examples. – tcode Jan 03 '18 at 16:21
  • 1
    Showing us the result of `str(info)` would be helpful, but I'd guess you want `plot(table(info))` or `barplot(table(info))`. – user2554330 Jan 03 '18 at 16:21
  • @LyzandeR Thank you very much, your answer has worked. Please excuse my beginner knowledge, but why did adding table(info) work and info on it's own did not? – tcode Jan 03 '18 at 16:26
  • 2
    try running `table(info)` on your console to see what happens. Also, read `?table` – LyzandeR Jan 03 '18 at 16:27
  • Why the down vote? It seems Stackoverflow is becoming renown for this. My question was a very genuine one in which I explained what I was attempting to do as well as supplying sample code and sample input. The person who down voted this needs to visit https://stackoverflow.com/company and remind themselves of what this website is all about. – tcode Jan 04 '18 at 16:38

1 Answers1

3

try this, should work:

barplot(table(info))
Felix.B
  • 306
  • 2
  • 8