Guest User

Untitled

a guest
Dec 11th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. base <- ggplot() +
  2. scale_x_continuous(breaks = seq(45, 360, 45), limits = c(0, 360)) +
  3. scale_y_continuous(breaks = seq(0, 1, 0.2), limits = c(0, 1)) +
  4. coord_polar(theta = "x", start = 1.5 * pi, direction = -1)
  5.  
  6. base + geom_rect(aes(xmin = 340, xmax = 380, ymin = 0.4, ymax = 0.6),
  7. color = "darkblue", fill = "steelblue")
  8. #> Warning message:
  9. #> Removed 1 rows containing missing values (geom_rect).
  10.  
  11. base + geom_rect(aes(xmin = 340, xmax = 380 %% 360, ymin = 0.4, ymax = 0.6),
  12. color = "darkblue", fill = "steelblue")
  13.  
  14. base + geom_rect(aes(xmin = c(350, 0), xmax = c(360, 10), ymin = 0.4, ymax = 0.6),
  15. color = "darkblue", fill = "steelblue")
  16.  
  17. ggplot() +
  18. scale_x_continuous(breaks = seq(45, 360, 45)) +
  19. scale_y_continuous(breaks = seq(0, 1, 0.2), limits = c(0, 1)) +
  20. coord_cartesian(xlim = c(0, 360)) +
  21. coord_polar(theta = "x", start = 1.5 * pi, direction = -1) +
  22. geom_rect(aes(xmin = 340, xmax = 380, ymin = 0.4, ymax = 0.6),
  23. color = "darkblue", fill = "steelblue")
  24.  
  25. ggplot() +
  26. scale_x_continuous(breaks = seq(45, 360, 45)) +
  27. scale_y_continuous(breaks = seq(0, 1, 0.2), limits = c(0, 1)) +
  28. coord_polar(theta = "x", start = 1.5 * pi, direction = -1) +
  29. coord_cartesian(xlim = c(0, 360)) +
  30. geom_rect(aes(xmin = 340, xmax = 380, ymin = 0.4, ymax = 0.6),
  31. color = "darkblue", fill = "steelblue")
  32.  
  33. library(ggforce)
  34. library(dplyr)
  35.  
  36. data_deg <- data.frame(xmin = 340,
  37. xmax = 380,
  38. ymin = 0.4,
  39. ymax = 0.6)
  40.  
  41. offset = 90 # by how much are angles offset
  42. dir = 1 # should we go counterclockwise (1) or clockwise (-1)
  43.  
  44. # convert angles from degrees into radians, apply offset and direction
  45. data_rad <- mutate(data_deg,
  46. xmin = dir*2*pi*(xmin + offset)/360,
  47. xmax = dir*2*pi*(xmax + offset)/360)
  48.  
  49. ggplot(data_rad) + geom_arc_bar(aes(x0 = 0, y0 = 0, r0 = ymin, r = ymax,
  50. start = xmin, end = xmax),
  51. color = "darkblue", fill = "steelblue") +
  52. scale_x_continuous(limits = c(-1, 1)) +
  53. scale_y_continuous(limits = c(-1, 1)) +
  54. coord_fixed()
Add Comment
Please, Sign In to add comment