0

Here in zomato folder there are 4 csv( bengoli, chinese, italian and panjabi)file. I am comparing these files with positive and negative word text file using lexicom based sentiment analysis.everything is working well , also i am getting values of a, c, e , g very perfectly. but when it comes to plot it is giving me this error

Don't know how to automatically pick scale for object of type list. Defaulting to continuous. Error: geom_bar requires the following missing aesthetics: y

 library(stringr)
    library(ggplot2)
    library(tm)


     src <- DirSource("./Data/foodwise/zomato")
        docs <- Corpus(src)
        docs <- tm_map(docs, removePunctuation)
        docs <- tm_map(docs,content_transformer(tolower))
        docs <- tm_map(docs, removeNumbers)
        docs <- tm_map(docs, removeWords,stopwords("english"))
        docs <- tm_map(docs, stripWhitespace)
        docs <- tm_map(docs, stemDocument)
        writeCorpus(docs, path="./Data")

texts <- readLines("./Data/zomato bengoli.csv.txt")
        opinion.lexicon.pos <- scan('./Data/positive-word.txt', what='character', comment.char = ';')
        opinion.lexicon.neg <- scan('./Data/negative-word.txt', what='character', comment.char = ';')
        jj <- str_split(texts, pattern="\\s+")
        a <- lapply(jj,function(x){sum(!is.na(match(x,opinion.lexicon.pos)))})
        texts1 <- readLines("./Data/zomato chinese.csv.txt")
        jj <- str_split(texts1, pattern="\\s+")
        c <- lapply(jj,function(x){sum(!is.na(match(x,opinion.lexicon.pos)))})

        texts2 <- readLines("./Data/zomato Italian.csv.txt")
        jj <- str_split(texts2, pattern="\\s+")
        e <- lapply(jj,function(x){sum(!is.na(match(x,opinion.lexicon.pos)))})

        texts3 <- readLines("./Data/zomato panjabi.csv.txt")
        jj <- str_split(texts3, pattern="\\s+")
        g <- lapply(jj,function(x){sum(!is.na(match(x,opinion.lexicon.pos)))})
        x <-c("Bengoli", "Chinese", "Italian", "Panjabi")
        y <- c(a, c ,e, g)
        data <- data.frame(x, y)
        ggplot(data, aes(x, y)) + geom_bar(stat = "identity",aes(fill = x)) + xlab("Cuisines") + ylab("Total count") + ggtitle("")+ scale_fill_manual("Cuisines", values = c("Italian" = "lightpink", "Panjabi" = "lightblue", "Chinese" = "darkgrey", "Bengoli"="lightgreen"))
NRR
  • 83
  • 2
  • 3
  • 12
  • 2
    Welcome to SO. First: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example Then to your question: I guess the error message is pretty much self explanatory. You need to provide an "y" which is continuous. Or you use stat = 'count', or geom_count – tjebo Jun 25 '18 at 13:19
  • 1
    `lapply` return an object of class `list`. This means that your objects `a`, `c`, `e`, and `g` are lists, so `y` is a list too. `ggplot` doesn't work well with lists, which is what the "*Don't know how to automatically pick scale for object of type list*" is saying. It's very hard to help you without a reproducible example and a description of your goal in words. If you need more help than these comments, check out Tjebo's link and give us a reproducible example to work with. – Gregor Thomas Jun 25 '18 at 13:21

1 Answers1

1

As was mentioned we really need a reproducible example to do a good job answering but I will try based on what I think you are asking

Your main problem is that you a, c, e and g are all lists so y is also a list. You need to convert them to numeric and then sum if you want a total

jj <- list("Bengoli","English", "Bengoli")
g <- lapply(jj,function(i){sum(!is.na(match(i,"Bengoli")))})
# this is a list:
g

g2 <- sum(unlist(g))
# Now it is a number which you can supply to ggplot
g2

x <-c("Bengoli", "Chinese", "Italian", "Panjabi")
y <- c(g2,4,3,6)

data <- data.frame(x, y)
ggplot(data, aes(x, y)) + 
  geom_bar(stat = "identity",aes(fill = x)) + 
  xlab("Cuisines") + 
  ylab("Total count") + 
  scale_fill_manual("Cuisines",
                    values = c("Italian" = "lightpink",
                               "Panjabi" = "lightblue", 
                               "Chinese" = "darkgrey", 
                               "Bengoli"="lightgreen"))
see24
  • 1,097
  • 10
  • 21
  • sorry i have updated my question now. hope u will get what i mean to say ....i am getting the value of a, c, e , g very perfectly.but when it comes to ggplot it is showing me an error – NRR Jun 25 '18 at 13:50
  • if you write `class(g)` and `class(y)` what do you get? – see24 Jun 25 '18 at 13:55
  • ohh my god after writing class(y) i am getting the exact output. thank you so much – NRR Jun 25 '18 at 13:58