2012-01-21 18 views
7

के शीर्ष पर अपने पाठ हो रही बस इस ओवरलैप लेबलिंग ठीक करने की कोशिश:पाई साजिश एक दूसरे को

मेरे कोड:

values=c(164241,179670) 
    labels=c("Private", "Public") 
    colors=c("#cccccc", "#aaaaaa") 
    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) 

    pie <- ggplot(values, aes(x = "", y = val, fill = Type)) + geom_bar(width = 1) + 
      geom_text(aes(y = **val + 1**, **hjust=0.5**, **vjust=-0.5**, label = percent), colour="#333333", face="bold", size=10) + 
      coord_polar(theta = "y") + ylab(NULL) + xlab(NULL) + 
      scale_fill_manual(values = graph$colors) + labs(fill = graph$categoriesName) + 
      opts(title = graph$title, 
       axis.text.x = NULL, 
       plot.margin = unit(c(0,0,0,0), "lines"), 
       plot.title = theme_text(face="bold", size=14), 
       panel.background = theme_rect(fill = "white", colour = NA)) 
    print(pie) 

मूल्यों तारांकन द्वारा चिह्नित (साथ खिलवाड़ की कोशिश की * * **) लेकिन कहीं भी नहीं मिला है। किसी भी मदद की सराहना की।

उत्तर

14

यहाँ एक उदाहरण है:

pie <- ggplot(values, aes(x = "", y = val, fill = Type)) + 
    geom_bar(width = 1) + 
    geom_text(aes(y = val/2 + c(0, cumsum(val)[-length(val)]), label = percent), size=10) 
pie + coord_polar(theta = "y") 

enter image description here

शायद यह आप समझ यह कैसे काम में मदद मिलेगी:

pie + coord_polar(theta = "y") + 
    geom_text(aes(y = seq(1, sum(values$val), length = 10), label = letters[1:10])) 

enter image description here

+0

धन्यवाद! वास्तव में उपयोगी है। – fabiopedrosa

+0

क्या आप जानते हैं कि उन्हें बाहर और कैसे रखा जाए? पाठ त्रिज्या बढ़ाएं। – fabiopedrosa

+0

'geom_text (aes (x = 1.3, y = ... ' – kohske

संबंधित मुद्दे