Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- base <- ggplot() +
- scale_x_continuous(breaks = seq(45, 360, 45), limits = c(0, 360)) +
- scale_y_continuous(breaks = seq(0, 1, 0.2), limits = c(0, 1)) +
- coord_polar(theta = "x", start = 1.5 * pi, direction = -1)
- base + geom_rect(aes(xmin = 340, xmax = 380, ymin = 0.4, ymax = 0.6),
- color = "darkblue", fill = "steelblue")
- #> Warning message:
- #> Removed 1 rows containing missing values (geom_rect).
- base + geom_rect(aes(xmin = 340, xmax = 380 %% 360, ymin = 0.4, ymax = 0.6),
- color = "darkblue", fill = "steelblue")
- base + geom_rect(aes(xmin = c(350, 0), xmax = c(360, 10), ymin = 0.4, ymax = 0.6),
- color = "darkblue", fill = "steelblue")
- ggplot() +
- scale_x_continuous(breaks = seq(45, 360, 45)) +
- scale_y_continuous(breaks = seq(0, 1, 0.2), limits = c(0, 1)) +
- coord_cartesian(xlim = c(0, 360)) +
- coord_polar(theta = "x", start = 1.5 * pi, direction = -1) +
- geom_rect(aes(xmin = 340, xmax = 380, ymin = 0.4, ymax = 0.6),
- color = "darkblue", fill = "steelblue")
- ggplot() +
- scale_x_continuous(breaks = seq(45, 360, 45)) +
- scale_y_continuous(breaks = seq(0, 1, 0.2), limits = c(0, 1)) +
- coord_polar(theta = "x", start = 1.5 * pi, direction = -1) +
- coord_cartesian(xlim = c(0, 360)) +
- geom_rect(aes(xmin = 340, xmax = 380, ymin = 0.4, ymax = 0.6),
- color = "darkblue", fill = "steelblue")
- library(ggforce)
- library(dplyr)
- data_deg <- data.frame(xmin = 340,
- xmax = 380,
- ymin = 0.4,
- ymax = 0.6)
- offset = 90 # by how much are angles offset
- dir = 1 # should we go counterclockwise (1) or clockwise (-1)
- # convert angles from degrees into radians, apply offset and direction
- data_rad <- mutate(data_deg,
- xmin = dir*2*pi*(xmin + offset)/360,
- xmax = dir*2*pi*(xmax + offset)/360)
- ggplot(data_rad) + geom_arc_bar(aes(x0 = 0, y0 = 0, r0 = ymin, r = ymax,
- start = xmin, end = xmax),
- color = "darkblue", fill = "steelblue") +
- scale_x_continuous(limits = c(-1, 1)) +
- scale_y_continuous(limits = c(-1, 1)) +
- coord_fixed()
Add Comment
Please, Sign In to add comment