1

I am using the follwing code:

x<-ggplot(masterdata,
              aes(x=reorder(Species,Species,
                            function(x)-length(x)))) +
      labs(x = "",
           y = "Frequency",
           title = "Species analysed: number of observations")+
      geom_bar()+
      theme_bw()+
      theme(axis.text.x=element_text(angle =-45, hjust = 0))
    x

...To produce this graphic:

enter image description here

However the names of the species at the right-bottom of the graph are cutted out from the image. I simply need a way to make the graph larger so to include also these complete names (I want to keep the angle of the text to -45).

(Note, the graphics is cutting out the names no matter on the size I am exporting my image from R)

Gabriele Midolo
  • 231
  • 1
  • 9

1 Answers1

2

Increase the plot margin on the right of your plot:

+ theme(plot.margin = unit(c(0,2,0,0), "lines")) #I choose 2 randomly, adapt to your need

Then if it still doesn't work, you need to use:

gb_plot <- ggplot_build(x)
gt_plot <- ggplot_gtable(gb_plot)
gt_plot$layout$clip[gt_plot$layout$name=="panel"] <- "off" 
grid.draw(gt_plot)

It should work, but I cannot test since your example is not reproductible (see How to make a great R reproducible example?)

Community
  • 1
  • 1
timat
  • 1,480
  • 13
  • 17