我有两个显示相同数据的条形图。每个 x 轴标签显示一个条形,它是输出集和输入集的总和。我的另一个需要将每个 x 轴标签的输入和输出数据分成两个相邻的条形。
从我在其他示例中看到的数据被合并到一个数组中,然后成对绘制。我尝试将两组合并为一组,但无法使其工作。
这是我绘制条形的方法:
svg.selectAll(".bar")
.data(options.series[i].data)
.enter().append("rect")
.attr("class", "bar")
.attr("class", function(d) {
if (d < 0) {
return "bar positive";
} else {
return "bar negative";
}
})
.attr("height", function(d) {
return Math.abs(yScale(d) - yScale(0));
})
.attr("y", function(d) {
if (d > 0) {
return yScale(d);
} else {
return yScale(0);
}
// return yScale(d)
})
.attr("width", (xScale.bandwidth()))
.attr("x", function(d, j) {
return xScale(options.labels[j])
})
.on('mouseover', function(d, j){
d3.select(this).style("opacity", 0.6);
tip.show(d, j);
})
.on('mouseout', function(d, j){ …Run Code Online (Sandbox Code Playgroud) 有人可以告诉我这里出了什么问题吗
\n#stemming all the words to their root word\nstemmer = SnowballStemmer(language='english')\nstem=[]\nfor word in lines:\n stem.append(stemmer.stem(word))\nstem[:20]\n#removes stopwords (very common words in a sentence)\nstem2 = []\nfor word in stem:\n if word not in nlp.Defaults.stop_words:\n stem2.append(word)\n#creates a new dataframe for the stem and shows the count of the most used words\ndf = pd.DataFrame(stem2)\ndf=df[0].value_counts()\ndf #shows the new dataframe\nRun Code Online (Sandbox Code Playgroud)\n我不知道这里出了什么问题,当我运行这些代码时遇到的错误 \xe2\xac\x87\xe2\xac\x87\xe2\xac\x87
\n#plots the top 20 used words\ndf = df[:20]\nplt.figure(figsize=(10,5))\nsns.barplot(df.values, df.index, alpha=0.8)\nplt.title('Top Words Overall')\nplt.xlabel('Count of words', fontsize=12)\nplt.ylabel('Word from Tweet', fontsize=12)\nplt.show()\nRun Code Online (Sandbox Code Playgroud)\n然后得到这些错误
\n …构建条形图以比较两组数据的最佳方法是什么?
例如数据集:
Number <- c(1,2,3,4)
Yresult <- c(1233,223,2223,4455)
Xresult <- c(1223,334,4421,0)
nyx <- data.frame(Number, Yresult, Xresult)
Run Code Online (Sandbox Code Playgroud)
我想要的是横跨X的数字和彼此相邻的条形,代表各个X和Y值
我的数据看起来像
language tone count tone_percent label_pos pos
1 c positive 3460 36.16977 18.08488 7
2 c neutral 2046 21.38825 46.86389 7
3 c negative 4060 42.44198 78.77901 7
4 c# positive 3732 41.26949 20.63475 3
5 c# neutral 1832 20.25876 51.39887 3
6 c# negative 3479 38.47175 80.76413 3
7 c++ positive 3136 33.13960 16.56980 8
8 c++ neutral 2008 21.21949 43.74934 8
9 c++ negative 4319 45.64092 77.17954 8
Run Code Online (Sandbox Code Playgroud)
我一直在尝试使用 ggplot2 条形图将它们可视化:
p <-ggplot() + theme_bw() + geom_bar(aes(y=tone_percent, x=reorder(language, …Run Code Online (Sandbox Code Playgroud)