Guest User

Untitled

a guest
Oct 23rd, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.10 KB | None | 0 0
  1. dput(BRCA_R_Y_4)
  2.  
  3. (list(Group = c("1. General", "1. General", "1. General",
  4. "1. General", "1. General", "1. General", "1. General", "2. Cancer",
  5. "2. Cancer", "2. Cancer", "2. Cancer", "2. Cancer", "2. Cancer",
  6. "2. Cancer", "3. Clinicians", "3. Clinicians", "3. Clinicians",
  7. "3. Clinicians", "3. Clinicians", "3. Clinicians", "3. Clinicians",
  8. "4. Researchers", "4. Researchers", "4. Researchers", "4. Researchers",
  9. "4. Researchers", "4. Researchers", "4. Researchers"),
  10.  
  11.  
  12. Reasons = c( "1. Burdened by the cost", "2. Believe I would not develop breast cancer ",
  13. "3. I don’t have breast cancer yet (it won’t be too late to treat afterwards)",
  14. "4. Worried about the side effects", "5. Have childbirth plans",
  15. "6. Do not trust test result", "7. Other", "1. Burdened by the cost",
  16. "2. Believe I would not develop breast cancer ", "3. I don’t have breast cancer yet (it won’t be too late to treat afterwards)",
  17. "4. Worried about the side effects", "5. Have childbirth plans",
  18. "6. Do not trust test result", "7. Other", "1. Burdened by the cost",
  19. "2. Believe I would not develop breast cancer ", "3. I don’t have breast cancer yet (it won’t be too late to treat afterwards)",
  20. "4. Worried about the side effects", "5. Have childbirth plans",
  21. "6. Do not trust test result", "7. Other", "1. Burdened by the cost",
  22. "2. Believe I would not develop breast cancer ", "3. I don’t have breast cancer yet (it won’t be too late to treat afterwards)",
  23. "4. Worried about the side effects", "5. Have childbirth plans",
  24. "6. Do not trust test result", "7. Other"),
  25. Percent = c(8.1130355515041,16.9553327256153, 57.0647219690064, 12.1239744758432, 2.91704649042844,
  26. 2.73473108477666, 0.0911577028258888, 3.85304659498208, 6.00358422939068,
  27. 73.7455197132617, 13.1720430107527, 0.896057347670251, 1.88172043010753,
  28. 0.448028673835125, 1.40845070422535, 2.8169014084507, 78.8732394366197,
  29. 2.8169014084507, 4.22535211267606, 0, 9.85915492957746, 1.63265306122449,
  30. 6.53061224489796, 71.8367346938775, 6.93877551020408, 6.12244897959184,
  31. 2.04081632653061, 4.89795918367347)), row.names = c(NA, -28L), class = c("tbl_df",
  32. "tbl", "data.frame"))
  33.  
  34. dat_pies4 <- left_join(BRCA_R_Y_4,
  35. BRCA_R_Y_4 %>%
  36. group_by(Group) %>%
  37. summarize(Cnt_total = sum(Percent))) %>%
  38. group_by(Group) %>%
  39. mutate(end_angle = 2*pi*cumsum(Percent)/Cnt_total, each pie slice
  40. start_angle = lag(end_angle, default = 0), each pie slice
  41. mid_angle = 0.5*(start_angle + end_angle))
  42.  
  43. rpie = 1
  44. rlabel = 0.6
  45.  
  46. dat_pies4 <- mutate(dat_pies4,
  47. hjust = ifelse(mid_angle>pi, 1, 0),
  48. vjust = ifelse(mid_angle<pi/2 | mid_angle>3*pi/2, 0, 1))
  49.  
  50. rlabel = 1.05 * rpie # now we place labels outside of the pies
  51.  
  52. pie.4 <-
  53. ggplot(dat_pies4) +
  54. geom_arc_bar(aes(x0 = 0, y0 = 0, r0 = 0, r = rpie,
  55. start = start_angle, end = end_angle, fill = Reasons))+
  56. geom_text(aes(x = rlabel*sin(mid_angle), y = rlabel*cos(mid_angle), label = paste0 (round(Percent), "%"),
  57. hjust = hjust, vjust = vjust)) +
  58. coord_fixed() +
  59. scale_x_continuous(limits = c(-1.5, 1.5), name = "", breaks = NULL, labels = NULL) +
  60. scale_y_continuous(limits = c(-1.5, 1.5), name = "", breaks = NULL, labels = NULL) +
  61. facet_grid(.~Group, switch = "both")+
  62. theme_void()+
  63. scale_fill_grey()+
  64. theme(legend.position="bottom", legend.direction="vertical", legend.margin = margin(30, 0, 10, 0))+
  65. theme(plot.title = element_text(size = 12, hjust = 0.5))+
  66. labs(title = "<why do not want RRM>")+
  67. guides (fill = guide_legend (title.theme = element_text (face = "bold")))
  68.  
  69. pie.4
Add Comment
Please, Sign In to add comment