[R] Why do we get “Don't know how to add o to a plot” Error?

Mohan V mohan221213 at gmail.com
Wed Oct 19 08:31:17 CEST 2016


Hello All,

Trying to implement the twitter sentiment analysis. Everything worked fine,
but when I try to make Barplots of tweets and getting the error as

    Error: Don't know how to add o to a plot

When i tried the first time it given me the proper output. But after that
it is giving me the above error

I would like to know why do we get the above error. In my case I am getting
this error in below cases.

# add variables to data frame
scores$drink = factor(rep(c("wine", "beer", "coffee", "soda"), nd))
scores$very.pos = as.numeric(scores$score >= 2)
scores$very.neg = as.numeric(scores$score <= -2)
# how many very positives and very negatives
numpos = sum(scores$very.pos)
numneg = sum(scores$very.neg)
# global score
global_score = round( 100 * numpos / (numpos + numneg) )
# colors
cols = c("#7CAE00", "#00BFC4", "#F8766D", "#C77CFF")
names(cols) = c("beer", "coffee", "soda", "wine")
1)  # barplot of average score
meanscore = tapply(scores$score, scores$drink, mean)
df = data.frame(drink=names(meanscore), meanscore=meanscore)
df$drinks <- reorder(df$drink, df$meanscore)

ggplot(df, aes(y=meanscore)) +
geom_bar(data=df, aes(x=drinks, fill=drinks)) +
scale_fill_manual(values=cols[order(df$meanscore)]) +
opts(title = "Average Sentiment Score",
    legend.position = "none")2)  # barplot of average very positive
drink_pos = ddply(scores, .(drink), summarise, mean_pos=mean(very.pos))
drink_pos$drinks <- reorder(drink_pos$drink, drink_pos$mean_pos)

ggplot(drink_pos, aes(y=mean_pos)) +
geom_bar(data=drink_pos, aes(x=drinks, fill=drinks)) +
scale_fill_manual(values=cols[order(drink_pos$mean_pos)]) +
options(title = "Average Very Positive Sentiment Score",
    legend.position = "none")
3) # barplot of average very negative
drink_neg = ddply(scores, .(drink), summarise, mean_neg=mean(very.neg))
drink_neg$drinks <- reorder(drink_neg$drink, drink_neg$mean_neg)

ggplot(drink_neg, aes(y=mean_neg)) +
geom_bar(data=drink_neg, aes(x=drinks, fill=drinks)) +
scale_fill_manual(values=cols[order(drink_neg$mean_neg)]) +
options(title = "Average Very Negative Sentiment Score",
legend.position = "none")

Above in all the three cases I am getting the same issue. please suggest me
why I am getting this error. How can I solve it.

Please suggest me.

Thanks in advance,

Mohan.V

	[[alternative HTML version deleted]]



More information about the R-help mailing list