Hello,
I have an excel datasheet that I want to create a stacked histogram with percentages with. I think I have the data setup in excel the way it needs to be in order to create the plot but I am running into an issue.
A tibble: 6 × 5
IssueArea Era1 Era2 Era3 Era4
1 attorneys 0 1 1 3
2 civil rights 0 11 41 37
3 criminal procedure 0 10 11 9
4 due process 7 54 14 18
5 economic activity 35 468 46 20
6 federal taxation 0 3 1 0
.....and so on.
I want to first, compute the percentages and then stack the percentages by IssueArea in one histogram.
When I type str (dataset name) it shows:
str(breadth_collapsed_davia)
tibble [14 × 5] (S3: tbl_df/tbl/data.frame)
IssueArea: chr [1:14] "attorneys" "civil rights" "criminal procedure" "due process" ...
Era1 : num [1:14] 0 0 0 7 35 0 7 2 1 17 ...
Era2 : num [1:14] 1 11 10 54 468 3 19 3 4 197 ...
Era3 : num [1:14] 1 41 11 14 46 1 8 38 0 23 ...
$ Era4 : num [1:14] 3 37 9 18 20 0 5 35 0 18 ...
However, when I try to move to calculating the percents in each era (my time variable), I get the following error:
summarise(n = sum(Era1)) %>%
- mutate(percentage = n / sum(n))
Error: object 'Era1' not found
I'm fairly sure this is an easy fix, but I only use R for ggplot so am not sure exactly what steps I need to take to read the data in correctly.