Reputation: 603
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)
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:
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.
EDIT: reduced questions
Upvotes: 1
Views: 2423
Reputation: 603
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
Upvotes: 1