GeomSectorPanel {ggsector} | R Documentation |
ggplot sector
Description
Draw sector with ggplot2.
Usage
geom_sector(
mapping = NULL,
data = NULL,
stat = "identity",
position = "identity",
...,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
individual = FALSE,
verbose = TRUE
)
Arguments
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer, as a string. |
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function. |
... |
Other arguments passed on to |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
individual |
Logical, default is FALSE. When "individual=FALSE", draw very quickly with a vector form, when "individual=TRUE", draw individually at a slower speed. Anyway, for better presentation, please add coord_fixed(). |
verbose |
Logical, default is TRUE. Whether to display reminder information. |
Details
When "individual=FALSE", draw very quickly with a vector form, when "individual=TRUE", draw individually at a slower speed.
The required parameters in mapping are "x", "y", "theta", and the additional modifiable parameters are "r", "start", "r_start", "type", "colour", "fill", "ratio", "size" for line size, "linetype".
When there is coord_fixed(), r = 0.5 means that the sector-shaped background circle just fills the entire cell
The ratio
parameter is still an experimental parameter,
if it is not necessary, please do not set it yourself.
The ratio
parameter only works when individual = FALSE
.
When ratio
is null, it will be auto calculated.
For better display effect, please always add coord_fixed()
.
For details, please check the grid.sector()
.
For more details, please type vignette("ggsector")
.
Value
ggplot object
Examples
## 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())
#################### 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())