Hi there! New to R here and really needing some help! I've been at this for a week
First of all, here is my data:
dput(head(merged_data_ctrl_tbl))
So! I would like to make a bar chart in order to compare the means of some data I have gathered. So far I have one big dataset that contains my entire corpus (which contains documents from 4 major newspapers). They are separated in a column entitled "newspaper" where I have assigned the correct newspaper name to the correct document. I also have 5 columns that correspond to the frequency of foundation words found in each document. There are 5 foundations: Care, Fairness, Authority, Loyalty and Sanctity. I hope you are still baring with me! I'm still not sure how to explain it succintly.
Each document has a frequency for each foundation. I have managed to describe the data in order to find out the Mean value of the frequency of each foundation word by newspaper, and I would like this in a bar chart. I know how to construct one, but I do not know how to turn my foundations into one categorical variable that I can then use the fill() function with "newspaper" in order to get a general comparison. How do I do this?
I tried this:
df_2 <- pivot_longer(data = merged_data_ctrl_tbl, cols = carePer100Words:sanctityPer100Words, names_to = "Foundation", values_to = "Mean")
df_2
ggplot(data = df_2) +
geom_bar(mapping = aes(x = Foundation, fill= newspaper), position= "dodge")
But it only gave me the Mean of each document, not overall per newspaper, and when put into a bar chart, it only gave me the count of each. Not very interesting! I also only want the variables that say "Per100Words" and don't know how to exclude those that say "PerWord". I know I'm close but my brain isn't working and I have no idea how to create the new data set. I'm so sorry if I've written this badly, I'm not yet fluent in R Studio
Thank you immensely for any help possible, it means the world to me!