6

I am unable to move the axis labels (Field data, secondary data, etc) around on the below figure so that they are both big and fit entirely within the diagram. The entire code is below. Suggestions on what to do?

Coord_polar figure

Datasource<-c("Field data", "Participatory data", "Remotely sensed data", 
              "Remotely sensed secondary data", "Secondary data")
Number<-c(32,39,55,96,202)
Percentage<-c(11,14,19,34,70)
DF<-data.frame(Datasource, Number, Percentage)

FigDataSourcesFlower<-ggplot(data=DF, aes(x=Datasource, y=Percentage)) +
  geom_bar(stat="identity", fill = "blue") + theme_bw() + 
  geom_text(aes(y = Percentage + 2.5,label = Percentage)) +
  coord_polar() +
  theme(axis.text.x = element_text(size = 15), axis.text.y=element_blank(), axis.ticks=element_blank(), axis.title=element_blank())
FigDataSourcesFlower

I tried using hjust and vjust, but I don't think this is exactly what I am looking for as these are more for angle adjustments. I read that I might be able to use \n to break up the labels over two rows, hoping this will help them fit, but I am unsure how to do this.

joran
  • 169,992
  • 32
  • 429
  • 468
  • If you're having this problem after 2018 you might find it useful to check out the solutions suggestion in response to this [similar question](https://stackoverflow.com/questions/71125994/how-can-i-move-x-axis-labels-away-from-the-centre-of-a-ggplot-that-uses-coord-po/71129665#71129665) – Captain Hat Feb 16 '22 at 11:32

1 Answers1

8

This is the best I can do at the moment:

p<-ggplot(data=DF, aes(x=Datasource, y=Percentage)) +
    geom_bar(stat="identity", fill = "blue") + 
    geom_text(aes(y = Percentage + 2.5,label = Percentage)) +
    coord_polar() +
    theme_bw() + 
    theme(axis.text.x = element_text(size = 15), 
                axis.text.y=element_blank(), 
                axis.ticks=element_blank(), 
                axis.title=element_blank(),
                panel.border = element_blank())
p

library(grid)
gt <- ggplot_gtable(ggplot_build(p))
gt$layout$clip[gt$layout$name == "panel"] <- "off"
grid.draw(gt)

This idea is taken from this answer.

Community
  • 1
  • 1
joran
  • 169,992
  • 32
  • 429
  • 468