0

I have a data table, with one of the columns labelled vowel_no (for number of vowels). There are only two possible values - 2.minus or 3.plus (i.e. 2 or less than 2 AND 3 or more than 3). Another of the columns in the data table is for books (there are five possible values for this i.e. five different books). I want to compare the ratios of words with 2 or fewer vowels to words with 3 or more vowels across the 4 books. I would like to end up with a ggplot that looks a bit like the ones on this page: R - ggplot showing distribution of binary flag variable (0/1) over time as normalized bar chart (%). I'm trying this but not having any luck.

ggplot(dt(aes(book,vowel_no, fill = vowelcount))+
  geom_bar()+
  ggtitle("vowel count")+
  xlab("name of book")+
  ylab("vowel counts")

Thank you

maro
  • 33
  • 5
  • 1
    Welcome to SO! It would be easier to help you if you provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including a snippet of your data or some fake data. – stefan Apr 25 '22 at 13:40
  • 2
    We probably need data here to help you, but your syntax is wrong here. There should be a comma after `dt`, not an opening parenthesis. – Allan Cameron Apr 25 '22 at 13:41
  • 1
    This said. As is, your code will not work. The first line should be `ggplot(dt, aes(film,vowel_no, fill = vowelcount)) +` – stefan Apr 25 '22 at 13:41
  • Thank you so much everyone - the feedback re: my formatting was really helpful . I implemented it, and although it still didn't work, I realised it's because I forgot to include an important variable. The column which has the counts in it, i.e. row numbers (n)- so I ended up with this :ggplot(dt,aes(book,n,fill=vowel_no))+ geom_bar(stat="identity")+ ggtitle("vowel counts across books")+ xlab("book")+ ylab("vowel count") – maro Apr 25 '22 at 14:11
  • I'll update my post later to make it clearer! – maro Apr 25 '22 at 14:14

0 Answers0