简体   繁体   English

使用text = element_blank()时,向ggplot饼图中添加标题

[英]Add a title to a to a ggplot pie chart when text = element_blank() is used

I want to make a pie chart without any labels, but with a title. 我想制作一个没有标题但带有标题的饼图。

However, I do not manage to combine both requirements: or I have a pie chart without a title and without axis (left picture), or I have a pie chart with a title and axis (right picture). 但是,我无法同时兼顾这两个要求:或者我有一个没有标题,没有轴的饼图(左图),或者我有一个带有标题和轴的饼图(右图)。 See the picture below: 见下图: 派问题

Is it possible to add a title to the left picture, or remove the axis on the right picture? 是否可以在左侧图片上添加标题,或移除右侧图片上的轴?

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 CHART 饼形图

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

Try this (without text= but with axis.title and ggtitle ): 尝试以下操作(不使用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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM