以行为 X 轴的箱线图

Boxplot with Rows as X Axis

我在可视化我的数据集时遇到问题。我浏览了问题,但找不到适合自己的答案。 我的数据集有组名作为列和两行值。在这里,我包括了数据的图像:

我需要一个箱形图,其中 x 轴上的行值(“BodyGoal”和“BodySource”)和组作为条形图(这样对于每个 x 轴点将有 3 个条形图代表值来自每组)。基本上就是这样,最好有悬停条。

我非常确定这非常容易做到,但我是 R 的新手,而且由于大流行,我无法与老师进行太多互动,所以我真的需要一些帮助。提前致谢!

我 运行 两行,但都没有给我想要的解决方案:

barplot(t(bodydf), legend.text = T)(感谢 rawr),但是这让我所有的组都堆叠在一起,我需要它们并排 我也有这个,但这比我需要的还要远: ggplot(stack(bodydf), aes(x=ind, y=values)) +geom_boxplot()

好吧,我想通了!!为像我这样可能需要它的任何新手分享我的代码:

groups= c("Blind", "Blindfolded", "Sighted","Blind", "Blindfolded", "Sighted")
values = c(0.17, 0.03, 0.05, 0.21, 0.06, 0.03)

deneme = data.frame(groups, values)
deneme$speech = c("Body Goal","Body Goal","Body Goal", "Body Source","Body Source","Body Source")
ggplot(deneme, aes(x=speech, y=values, fill=groups)) + 
  geom_bar(stat="identity", position = "dodge", width = .5) +
  scale_fill_manual("legend", values= c("Blind" = "pink1", "Blindfolded"="slategray1", "Sighted" = "paleturquoise3")) +
  ggtitle("Body Oriented Speech") +
  labs( y= "Ratio per Relevant Clause", x="Speech Item") +
  theme(legend.position="bottom") +
  theme(legend.title = element_blank()) +
  theme(plot.title = element_text(hjust = 0.5))