1

I am having problems visualizing my data set. I skimmed through questions but couldn't quite find a suitable answer for myself. My data set has group names as columns and two rows of values. Here I am including an image of the data:

The original data

I need a boxplot with the row values on the x axis ("BodyGoal" and "BodySource") and the groups as bars (in such a way that for each x axis point there would be 3 bars representing the values from each group). Basically like this, preferably with hovering bars.

Desired outcome is this chart

I am so sure that this is super easy to do but I am new to R and due to the pandemic I don't get to interact with my teachers as much, so I really need some help with this. Thank you in advance!

I run two lines but neither is giving me the solution I want:

barplot(t(bodydf), legend.text = T) (thanks to rawr), however this is giving me all my groups stacked on top of each other, i need them to be side by side I also have this but this is even further away than what I require: ggplot(stack(bodydf), aes(x=ind, y=values)) +geom_boxplot()

SimgeO
  • 11
  • 3
  • 2
    please include a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with your question and use functions like `dput` to share data instead of images. you could try something like `barplot(t(data), legend.text = TRUE)` to get a barplot with rows on the x-axis – rawr Apr 19 '21 at 11:59
  • Thank you, I will do that now ^^ – SimgeO Apr 21 '21 at 12:54

1 Answers1

0

Well, I somehow figured it out!! Sharing my code for any newbie like myself who might need it:

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))
SimgeO
  • 11
  • 3