I have the following dataframe:
| group | Class | Maths | Science |
|---|---|---|---|
| Name1 | 7 | 74 | 78 |
| Name2 | 7 | 80 | 91 |
| Name3 | 6 | 69 | 80 |
I want to create different radar plots for the variables Maths and Science for each classes using R. eg: For the above dataframe, two radar plots should be created for two classes 7 and 6.
nrange <- 2
class <- c(7,6)
for (i in nrange){
plot <- ggradar::ggradar(df[i,2:3], values.radar = c(0, 50, 100), group.line.width = 1,
group.point.size = 2, legend.position = "bottom", plot.title=class[i])
}
plot
I using the above code. However, it is only creating the plot for the last row. Please help me with this issue.
Thanks a lot in advance!
You were almost there, but there were two little problems.
for(i in 2)which means it is only usingi=2. You can fix this by usingfor(i in 1:nrange)ploteach time through the loop. If you makeplota list and save each graph as a separate element in the list, then it should work.Created on 2023-02-03 by the reprex package (v2.0.1)
Putting Together with facet_wrap()
Created on 2023-02-06 by the reprex package (v2.0.1)