Это может быть то, что вы хотели создать:
library(tidyverse)
library(reshape2)
library(tm)
# your data
x <- tibble(Ticket = c(12345, 12346, 12347 ,12354, 12355),
Feedback = c("The resolution was proper", "The ticket was closed without notice", "Good" ,"He is highly reliable.", "He accomplished all tasks"),
Date = c("01-01-2019", "02-01-2019", "03-01-2019", "03-02-2019", "04-02-2019"),
Month = c("January", "January", "January", "February", "February"),
Rating = c(5,4,4,4,4))
# reading lists
negative <- read_tsv("negative.txt",col_names=F)$X1
positive <- read_tsv("positive.txt",col_names=F)$X1
str(positive) #positive words dictionary
str(negative) #negatiive words dictionary
sample_reviews <- x
# List-Conversion
sample_reviews <- split(sample_reviews, sample_reviews$Month)
# Your code executed for each month
x <- lapply(sample_reviews, function(x){
file <- x$Feedback
file <- tolower(file)
filee <- removeWords(file,stopwords("english"))
filee <- removePunctuation(filee)
filee <- stripWhitespace(filee)
filee <- removeNumbers(filee)
filr <- str_split(filee,pattern="\\s+")
fg <- unlist(str_split(filee,pattern="\\s+"))
match(fg,positive)
match(fg,negative)
a<-sum(!is.na(match(fg,positive)))
b<-sum(!is.na(match(fg,negative)))
c<- a+b
Positiveperc <- (a/c)*100
Negativeperc <- (b/c)*100
mat<-matrix(c(Positiveperc,Negativeperc),ncol=1)
colnames(mat) <- c('values')
rownames(mat) <- c('Positive','Negative')
dat<- cbind("Result"=rownames(mat), mat)
mydata<-data.frame(dat)
return(mydata)
})
# Add month as column
x <- lapply(names(x), function(names){
x[[names]]$Month <- names
return(x[[names]])
})
# transformation for plotting
x <- x %>%
bind_rows() %>%
mutate(Month = factor(Month, levels=c("January", "February")))
# plotting everything in the same plot
plot <- ggplot(x, aes(Result, values, fill=Month))+
geom_bar(stat="identity", position=position_dodge())
# show plot
plot
# adding a wrap, which creates different plots based on Month
plot + facet_wrap(~Month)
Это то, что вы получаете при использовании первого варианта:
И вот что вы добавляете facet_wrap()
:
Это то, что вы хотите произвести?