R:为什么我们得到“不知道如何添加o到情节”错误?

时间:2016-10-17 14:09:37

标签: r

尝试实施Twitter情绪分析。 一切都运行正常,但当我尝试制作推文的条形码并将错误视为

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

当我第一次尝试时,它给了我正确的输出。 但在那之后它给了我上面的错误

我想知道为什么会出现上述错误。 在我的情况下,我在以下情况下收到此错误。

# 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")

在所有这三种情况中,我都遇到了同样的问题。 请告诉我为什么我收到此错误。 我该怎么解决呢。

请建议我。

提前致谢,

Mohan.V

0 个答案:

没有答案