Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Circular line graph with groups

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading