I'm trying to replicate the chart linked below in r but have been unable to. I know that this probably isn't the best way to visualise the information but that's the task I have.
Any help would be great.
I'm trying to replicate the chart linked below in r but have been unable to. I know that this probably isn't the best way to visualise the information but that's the task I have.
Any help would be great.
As both comments say, the expectation on SO is that you share data and some code in a minimal example of how far you have gotten. That said, here is a crude starting point, based in part on pie charts in R:
titles <- c(38, 244, 34, 20, 25)
position <- c("Adm","GC","Lawyer","Lawyer2", "Other")
piedf <- cbind(titles, position)
dfpie <- data.frame(piedf)
ggplot(data=dfpie, aes(x=factor(1), y=titles, fill = factor(position))) +
geom_bar(width = .6, stat = "identity") +
labs(x = "", y = "") +
guides(fill = FALSE) +
coord_polar(theta="y") +
theme_bw()
As they say here, I leave it as an exercise for the OP to overlay a donut plot inside the larger pie chart.
you can reproduce the plot using the package ggsunburst
# install ggsunburst package
if (!require("ggplot2")) install.packages("ggplot2")
if (!require("rPython")) install.packages("rPython")
install.packages("http://genome.crg.es/~didac/ggsunburst/ggsunburst_0.0.9.tar.gz", repos=NULL, type="source")
library(ggsunburst)
# trying to replicate the data in your plot
df <- read.table(header = T, text = "
parent node size
Non-Domestic A 30
Non-Domestic B 10
Non-Domestic C 2
Domestic A 20
Domestic B 25
Domestic C 1
Transport A 10
Transport B 15
")
write.table(df, 'df.csv', row.names = F, sep = ",")
sb <- sunburst_data('df.csv', type="node_parent", sep = ",")
sunburst(sb, leaf_labels = F, node_labels = T, node_labels.min = 30, rects.fill.aes = "name") +
scale_fill_discrete(guide = F)