1

So I am happily using ggplot2. I am trying to make a graph with simple lines, big text for readability (It will be 3" wide in my paper). (using stock data for easiness)

#build data set
table2A<-mtcars[1:7,1:2]
table2B<-mtcars[1:7,1:2]
table2A$cyl<-rep(c("six"),7)
table2B$cyl<-rep(c("two"),7)
table2B$mpg<-sapply(table2B$mpg,function(x) x*1.5)
table2A$Text<-rownames(table2A)
table2B$Text<-rownames(table2B)
table2A<-rbind(table2A, table2B)

#graph
graph <- ggplot(table2A, aes(x=Text, y=mpg)) + geom_line(lwd=1.5,aes(group=cyl,linetype=cyl)) + labs(title="mpg by car, engine type") + labs(x="car name",y="")
graph + theme_classic() + theme(legend.key.width=unit(0.05,units="npc")) +
  theme (axis.line=element_line(size=1.5), axis.ticks=element_line(size=1.5), title=element_text(size=16), axis.text=element_text(size=12),     axis.text.x=element_text(angle=0))
ggsave(filename = "./graph.out.png", scale = 2.5, width = 3, height = 3/1.618, units="in", dpi=600)

Image, x-axis text labels overlap

This is no good, because you can't read the labels. I can change the code to axis.text.x=element_text(angle=45) And then I get this:

Image, x-axis labels cross x-axis

I can't have the text crossing the x axis, it isn't readable.

I have searched for examples, but I haven't found anything that works.

  1. Can I justify the x axis label text, so the end of text is below x axis?

EDIT: reduced questions

BAMF4bacon
  • 523
  • 1
  • 7
  • 21
  • Have you read the help for `element_text()`? It seems to me that maybe, you could use the `vjust` argument... It's just a slight change that has to be applied manually, but maybe it's all you need here. – maj Aug 21 '15 at 14:53
  • Looks like the same problem as here: http://stackoverflow.com/questions/14487188/increase-distance-between-text-and-title-on-the-y-axis – John Tarr Aug 21 '15 at 15:27

1 Answers1

1
axis.text.x=element_text(angle=45,vjust=0.5)

Note that vjust here ranges from 0 to 1.

EDIT: as commenter pointed out, angle was incorrect

BAMF4bacon
  • 523
  • 1
  • 7
  • 21