Chapter 6 geom_jjpie2
geom_jjpie2 almost is same as geom_jjpie . The geom_jjpie2 can totate the pie graph and produce a right circle.
the following we will illustrate how the geom_jjpie2 works.
6.1 prepare data
# test
<- cor(mtcars) %>%
cor_data data.frame() %>%
mutate(x = rownames(.)) %>%
melt(.,id.vars = "x")
<- cor_data %>% filter(variable %in% c('mpg','cyl','disp','hp'))
cor_datax
# add some value
$value2 <- rev(cor_datax$value) cor_datax
6.2 examples
rotate with angle arg:
library(ggnewscale)
ggplot(cor_datax,
aes(x = x,y = variable)) +
geom_jjpie2(aes(piefill = value,fill = value),
pie.theta = 180,
angle = 90,
add.circle = F,
width = 2) +
scale_fill_gradient(low = 'grey80',high = 'red') +
new_scale_fill() +
geom_jjpie2(aes(piefill = value2,fill = value2),
pie.theta = 180,
angle = 270,
add.circle = F,
width = 2) +
scale_fill_gradient(low = 'grey80',high = 'blue') +
coord_fixed()
rotate to vertical position:
ggplot(cor_datax,
aes(x = x,y = variable)) +
geom_jjpie2(aes(piefill = value,fill = value),
pie.theta = 180,
angle = 180,
add.circle = F,
width = 2) +
scale_fill_gradient(low = 'grey80',high = 'red') +
new_scale_fill() +
geom_jjpie2(aes(piefill = value2,fill = value2),
pie.theta = 180,
angle = 360,
add.circle = F,
width = 2) +
scale_fill_gradient(low = 'grey80',high = 'blue') +
coord_fixed()
make hollow circle:
ggplot(cor_datax,
aes(x = x,y = variable)) +
geom_jjpie2(aes(piefill = value,fill = value),
pie.theta = 180,
angle = 90,
add.circle = F,
width = 2) +
scale_fill_gradient(low = 'grey80',high = 'red') +
new_scale_fill() +
geom_jjpie2(aes(piefill = value2,fill = value2),
pie.theta = 180,
angle = 270,
add.circle = F,
circle.radius = 2,
hollow.fill = 'white',
width = 2) +
scale_fill_gradient(low = 'grey80',high = 'blue') +
coord_fixed() +
theme_bw()