I'm trying to create piechart similar to radial plot (plotrix), in ggplot2. Basically the slices would have different length.
radii <- c(2,3,2,1,3,1,2,3,2)
color <- c("lightgrey", "chartreuse", "lightgrey", "darkturquoise", "darkolivegreen3",
"orangered", "lightgrey", "darkseagreen1", "lightgrey")
radial.pie(radii, labels = NA, sector.colors = color,
show.grid = F, show.grid.labels = F ,show.radial.grid = T,
radial.labels = F, clockwise = T,start=3)
Is there an easy way to do this? The reason for doing it in ggplot is that I want to have a this piechart on top of a ggplot violin plot in one page using plot_grid.
This answer was copied from:
Making polar plots with ggplot2 by Carolyn Parkinson (April 10, 2015)
http://rstudio-pubs-static.s3.amazonaws.com/72298_c1ba7f77276a4f27a0f375cadc9fac5d.html
Basically, all you have to do is plot a bar plot with coord_ploar()
to make it this kind of radial plot:
require(ggplot2)
# function to compute standard error of mean
se <- function(x) sqrt(var(x)/length(x))
set.seed(9876)
DF <- data.frame(variable = as.factor(1:10),
value = sample(10, replace = TRUE))
ggplot(DF, aes(variable, value, fill = variable)) +
geom_bar(width = 1, stat = "identity", color = "white") +
geom_errorbar(aes(ymin = value - se(DF$value),
ymax = value + se(DF$value),
color = variable),
width = .2) +
scale_y_continuous(breaks = 0:nlevels(DF$variable)) +
theme_gray() +
theme(axis.ticks = element_blank(),
axis.text = element_blank(),
axis.title = element_blank(),
axis.line = element_blank()) +
coord_polar()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.