Home > Mobile >  Circular line graph with groups
Circular line graph with groups

Time:09-13

I have four dataframes that look like below:

      X    score.i    score.ii    score.iii  mm
  1:   1 -0.3958555 -0.3750726 -0.3378881  10
  2:   2 -0.3954955 -0.3799290 -0.3400876  15
  3:   3 -0.3962514 -0.3776692 -0.3401180  20
  4:   4 -0.4033265 -0.3764099 -0.3436115  25
  5:   5 -0.4035860 -0.3753792 -0.3426287  30
 ---                                         
186: 186 -0.4041035 -0.3767158 -0.3419871  80
187: 187 -0.4040643 -0.3767881 -0.3417620  85
188: 188 -0.4052228 -0.3766468 -0.3436883  90
189: 189 -0.4047009 -0.3767359 -0.3431591  95
190: 190 -0.4061497 -0.3766785 -0.3433624 100

How can I plot a circular line graph with aes(x=mm, y=score.i) for these four such that there is a gap between the lines for each dataframe?

CodePudding user response:

library(ggplot2)
library(dplyr)
library(tidyr)

df1 %>% 
  pivot_longer(-c(X, mm), names_to = "Variable", values_to = "Score") %>% 
 ggplot(., aes(x = mm, y = Score, color = Variable))  
  geom_line()  
  coord_polar()

Data:

read.table(text = 
"X   score.i    score.ii   score.iii  mm 
1   -0.3958555 -0.3750726 -0.3378881  10
2   -0.3954955 -0.3799290 -0.3400876  15
3   -0.3962514 -0.3776692 -0.3401180  20
4   -0.4033265 -0.3764099 -0.3436115  25
5   -0.4035860 -0.3753792 -0.3426287  30
186 -0.4041035 -0.3767158 -0.3419871  80
187 -0.4040643 -0.3767881 -0.3417620  85
188 -0.4052228 -0.3766468 -0.3436883  90
189 -0.4047009 -0.3767359 -0.3431591  95
190 -0.4061497 -0.3766785 -0.3433624 100", 
header = T, stringsAsFactors = F) -> df1
  • Related