## prepare data
library(ggsector)
library(reshape2)
df <- cor(mtcars)[1:3, 1:5] %>%
abs() %>%
melt(varnames = c("x", "y"))
###
## Note, for better display effect, please always add coord_fixed()
## Note, for better display effect, please always add coord_fixed()
## Note, for better display effect, please always add coord_fixed()
## theta
ggplot(df) +
## type = "percent", theta = 0-100
geom_sector(
aes(y, x, theta = value * 100),
type = "percent",
color = "blue",
individual = TRUE
) +
## type = "degree", theta = 0-360
geom_sector(
aes(y, x, theta = value * 360),
type = "degree",
color = "red",
alpha = 0.5,
individual = TRUE
) +
coord_fixed() +
theme_bw() +
theme(axis.title = element_blank())
## r
ggplot(df) +
geom_sector(
aes(y, x, theta = value * 100),
r = rep(c(0.15, 0.3, 0.45), 5),
fill = 2,
individual = TRUE
) +
coord_fixed() +
theme_bw() +
theme(axis.title = element_blank())
## start
ggplot(df) +
geom_sector(
aes(y, x, theta = value * 100),
start = rep(c(60, 40, 20), 5),
fill = 2,
individual = TRUE
) +
coord_fixed() +
theme_bw() +
theme(axis.title = element_blank())
## r_start
ggplot(df) +
geom_sector(
aes(y, x, theta = value * 100),
r_start = rep(c(0.15, 0.25, 0.35), 5),
fill = 2,
individual = TRUE
) +
coord_fixed() +
theme_bw() +
theme(axis.title = element_blank())
# \donttest{
#################### individual ###################
########## individual with coord_fixed() ##########
## `individual = TRUE` + coord_fixed()
# x = x, y = y
ggplot(rbind(
cbind(df, t1 = 1),
cbind(df[1:9, ], t1 = 2)
)) +
facet_wrap(~t1, ncol = 2) +
geom_sector(
aes(x, y),
theta = 75,
fill = 2,
r = 0.5,
individual = TRUE
) +
coord_fixed() +
theme_bw() +
theme(axis.title = element_blank())
# x = y, y =x
ggplot(rbind(
cbind(df, t1 = 1),
cbind(df[1:9, ], t1 = 2)
)) +
facet_wrap(~t1, ncol = 2) +
geom_sector(
aes(y, x),
theta = 75,
fill = 2,
r = 0.5,
individual = TRUE
) +
coord_fixed() +
theme_bw() +
theme(axis.title = element_blank())
## `individual = FALSE` + coord_fixed()
# x = x, y = y
ggplot(rbind(
cbind(df, t1 = 1),
cbind(df[1:9, ], t1 = 2)
)) +
facet_wrap(~t1, ncol = 2) +
geom_sector(
aes(x, y),
theta = 75,
fill = 2,
r = 0.5,
individual = FALSE
) +
coord_fixed() +
theme_bw() +
theme(axis.title = element_blank())
# x = y, y =x
ggplot(rbind(
cbind(df, t1 = 1),
cbind(df[1:9, ], t1 = 2)
)) +
facet_wrap(~t1, ncol = 2) +
geom_sector(
aes(y, x),
theta = 75,
fill = 2,
r = 0.5,
individual = TRUE
) +
coord_fixed() +
theme_bw() +
theme(axis.title = element_blank())
########## individual without coord_fixed() ##########
## If you are in a special situation and cannot use coord_fixed(),
## then it is recommended that you use `individual = TRUE` and
## the `r` parameter to fine-tune.
## Also, to reduce the radius, you need to try it manually.
## `individual = TRUE` without coord_fixed()
# x = x, y = y
ggplot(rbind(
cbind(df, t1 = 1),
cbind(df[1:9, ], t1 = 2)
)) +
facet_wrap(~t1, ncol = 2) +
geom_sector(
aes(x, y),
theta = 75,
fill = 2,
r = 0.35, ## To reduce the radius, you need to try it manually
individual = TRUE
) +
theme_bw() +
theme(axis.title = element_blank())
# x = y, y =x
ggplot(rbind(
cbind(df, t1 = 1),
cbind(df[1:9, ], t1 = 2)
)) +
facet_wrap(~t1, ncol = 2) +
geom_sector(
aes(y, x),
theta = 75,
fill = 2,
r = 0.25, ## To reduce the radius, you need to try it manually
individual = TRUE
) +
theme_bw() +
theme(axis.title = element_blank())
## `individual = FALSE`
## If you really want to use `individual = FALSE` without coord_fixed(),
## you might try the experimental parameter `ratio'
## You need to manually adjust the `ratio` value
## to prevent sector deformation.
# x = x, y = y
ggplot(rbind(
cbind(df, t1 = 1),
cbind(df[1:9, ], t1 = 2)
)) +
facet_wrap(~t1, ncol = 2) +
geom_sector(
aes(x, y),
theta = 75,
fill = 2,
r = 0.5,
## You need to manually adjust the `ratio` value
## to prevent sector deformation.
ratio = 1.6,
individual = FALSE
) +
theme_bw() +
theme(axis.title = element_blank())
# x = y, y =x
ggplot(rbind(
cbind(df, t1 = 1),
cbind(df[1:9, ], t1 = 2)
)) +
facet_wrap(~t1, ncol = 2) +
geom_sector(
aes(y, x),
theta = 75,
fill = 2,
r = 0.5,
## You need to manually adjust the `ratio` value
## to prevent sector deformation.
ratio = 1.6,
individual = FALSE
) +
# coord_fixed() +
theme_bw() +
theme(axis.title = element_blank())
# }
Run the code above in your browser using DataLab