【发布时间】:2015-08-21 14:32:31
【问题描述】:
所以我很高兴使用 ggplot2。我正在尝试用简单的线条和大文本制作一个图表以提高可读性(在我的论文中它将是 3 英寸宽)。(为了方便起见,使用股票数据)
#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)
这不好,因为你看不懂标签。 我可以将代码更改为 axis.text.x=element_text(角度=45) 然后我得到了这个:
我不能让文本穿过 x 轴,它不可读。
我已经搜索了示例,但没有找到任何可行的方法。
- 我可以证明 x 轴标签文本是合理的,所以文本的结尾在 x 轴下方吗?
编辑:减少问题
【问题讨论】:
-
您阅读过
element_text()的帮助吗?在我看来,也许您可以使用vjust参数...这只是一个必须手动应用的微小更改,但也许这就是您所需要的。 -
看起来和这里的问题一样:stackoverflow.com/questions/14487188/…