I am interested in merging 3 datasets using the Pivot_Longer function.
The data I have is as follows:
A_1930 <- data.frame(grade = c("A","B","C","D"), total = c(0.5,0.35,0.7,0.45), white = c(0.6, 0.2, 0.1, 0.3), black = c(0.4,0.25,0.6,0.35), imm = c(0.2, 0.3, 0.6, 0.5), year = c(1930,1930,1930,1930))
B_1990 <- data.frame(grade = c("A","B","C","D"), total = c(0.45,0.5,0.7,0.5), white = c(0.65, 0.3, 0.15, 0.35), black = c(0.4,0.2,0.55,0.5), imm = c(0.25, 0.4, 0.5, 0.6), year = c(1990,1990,1990,1990))
C_2020 <- data.frame(grade = c("A","B","C","D"), total = c(0.45,0.3,0.6,0.5), white = c(0.5, 0.4, 0.1, 0.25), black = c(0.45,0.5,0.35,0.5), imm = c(0.25, 0.3, 0.55, 0.25), year = c(2020,2020,2020,2020))
I am interested in merging the datasets into something that looks like the following: The final table would include all three datasets.
YEAR | GRADE | NAME | VALUE |
---|---|---|---|
1930 | A | total | 0.45 |
1930 | B | white | 0.5 |
1930 | C | black | 0.45 |
Next, I am interested in creating a graph that looks like the following: Graph Expectation. Though, I am open to alternative visualizations if they make more sense. Thanks for your help with this!