2016-03-01 101 views
1

我想制作饼图不带任何标签,但是带有标题。然而,我没有设法结合这两个要求:或者我有一个没有标题和没有轴的饼图(左图),或者我有一个带有标题和轴的饼图(右图)。看到下面的图片: pie problem当使用text = element_blank()时,为ggplot饼图添加标题

是否可以添加一个标题左图片,或删除右图片轴?

DATA

data<-structure(list(nuts0 = c("IT", "IT", "IT", "IT", "IT", "IT", 
         "IT", "IT", "IT", "IT"), variable = structure(1:10, .Label = c("percentage_irri10", 
                         "percentage_irri20", "percentage_irri30", "percentage_irri40", 
                         "percentage_irri50", "percentage_irri60", "percentage_irri70", 
                         "percentage_irri80", "percentage_irri90", "percentage_irri100" 
         ), class = "factor"), value = c(0.100915431560593, 0.0860941586748038, 
                 0.0695292066259808, 0.0662598081952921, 0.0745422842197036, 0.0512205754141238, 
                 0.0599389712292938, 0.047079337401918, 0.0551438535309503, 0.389276373147341 
         )), .Names = c("nuts0", "variable", "value"), row.names = c(10L, 
                        25L, 40L, 55L, 70L, 85L, 100L, 115L, 130L, 145L), class = "data.frame") 


percentlabelsIT<- round(100*data$value, 0) 
pielabelsIT<- paste(percentlabelsIT, "%", sep="") 
cols <- c("yellow","greenyellow","#00FF00", "#00C639","#00AA55", "#00718E", "#0055AA", "#001CE3","blue4","midnightblue") 

饼图

pie <- ggplot(data, aes(x = factor(1), fill = factor(percentlabelsIT))) + geom_bar(width = 1)+ 
    ggtitle("help")+ 
    theme(axis.text = element_blank(), 
     axis.ticks = element_blank(), 
     panel.grid = element_blank(), 
     legend.position="none", 
     line = element_blank(), 
     text = element_blank() 
)+ 
    scale_fill_manual(values=cols) 
l1<-pie + coord_polar(theta = "y") 
l1 

回答

1

试试这个(没有text=axis.titleggtitle):

pie <- ggplot(data, aes(x = factor(1), fill = factor(percentlabelsIT))) + geom_bar(width = 1)+ 
    ggtitle("help")+ 
    theme(axis.text = element_blank(), 
      axis.title = element_blank(), 
      axis.ticks = element_blank(), 
      panel.grid = element_blank(), 
      legend.position="none", 
      line = element_blank() 
    )+ 
    scale_fill_manual(values=cols) 
l1 <-pie + coord_polar(theta = "y") + ggtitle("kdfja") 
l1 
+0

非常感谢!不知道! – user33125