0

I am using this code:

ggplot2::ggplot(gtfDf, ggplot2::aes(x = type)) + 
  ggplot2::geom_bar(position = ggplot2::position_dodge(width = 2)) +
  ggplot2::xlab('Type of feature') + 
  ggplot2::ylab('Number of features') + 
  ggplot2::ggtitle('Number of features of each type in the GTF file')

to generate a plot in R. However, the labels overlap each other a bit. Does anybody know how I can space the columns more?

Richard Telford
  • 9,558
  • 6
  • 38
  • 51
charlesdarwin
  • 717
  • 1
  • 9
  • 16
  • You could check out https://stackoverflow.com/questions/1330989/rotating-and-spacing-axis-labels-in-ggplot2 – CPak Aug 01 '17 at 16:45
  • 3
    If you run `library(ggplot2)` before running your plot code, then you won't need to type `ggplot2::` on each line. – eipi10 Aug 01 '17 at 16:46

2 Answers2

0

Did you try simply make the graph bigger? You can use ggsave("filename.extension", width=x, height=y) to print the last active plot object (or specify it with the argument plot=plot_name), then simply play around with the size of your output until you're happy with it.
Not the smartest way, but since you probably want to play with the size for rendering in the end anyway...

Arthur Spoon
  • 442
  • 5
  • 18
0

The items on the x-axis have x values of 1, 2, 3, and so on, though you typically don’t refer to them by these numerical values. When you use geom_bar(width=0.9), it makes each group take up a total width of 0.9 on the x-axis so if you reduce this bar width you can space the columns more, try something like this:

library(ggplot2)
ggplot(gtfDf, aes(x = type)) +
geom_bar(width=0.5, position =position_dodge(0.5))
Andres
  • 2,413
  • 1
  • 13
  • 18