r - ggplot2 - piechart - value labels in reverse order -


i trying match labels pie chart ggplot2:

code:

values=c(59,4,4,11,26) labels=c("cata", "catb","catc","catd","cate") pos = cumsum(values)- values/2 graph <- data.frame(values, labels,pos)  categoriesname="access" percent_str <- paste(round(graph$values / sum(graph$values) * 100,1), "%", sep="")  values <- data.frame(val = graph$values, type = graph$labels, percent=percent_str, pos = graph$pos )  pie <- ggplot(values, aes(x = "", y = val, fill = type)) +    geom_bar(width = 1,stat="identity") +    geom_text(aes(x= "", y=pos, label = val), size=3)  pie + coord_polar(theta = "y") 

output: myoutput

i read these topics, without success:

starting in ggplot2 2.2.0, can use position_stack vjust = .5 center labels in stacked bars charts (and pie charts). no longer need calculate position outside of ggplot2. see news more details on these changes.

ggplot(values, aes(x = "", y = val, fill = type)) +      geom_bar(width = 1,stat="identity") +      geom_text(aes(label = val), size=3, position = position_stack(vjust = 0.5))  +      coord_polar(theta = "y") 

enter image description here


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -