将右侧的轴标签与ggplot2对齐 [英] Align axis label on the right with ggplot2

查看:267
本文介绍了将右侧的轴标签与ggplot2对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑下面的内容:

$ $ $ $ $ $ $ $ $ d = data.frame(y = rnorm(120),
x = rep c(bar,long category name,foo),each = 40))

ggplot(d,aes(x = x,y = y))+
geom_boxplot()+
theme(axis.text.x = element_text(size = 15,angle = 90))



x轴标签由标签的中心对齐。是否有可能在右侧自动对齐,以便每个标签都可以在图的下方结束? 解决方案



如何:

  ggplot(d,aes(x = x,y = y))+ geom_boxplot()+ 
theme(axis.text.x = element_text(size = 15,angle = 90,hjust = 0.95,vjust = 0.2))



您可以使用 hjust vjust 参数将标签移动到所需的位置。此外,如果您想将轴标签对准x轴,您可以更改 hjust = 1


Consider the following

d = data.frame(y=rnorm(120), 
               x=rep(c("bar", "long category name", "foo"), each=40))

ggplot(d,aes(x=x,y=y)) + 
    geom_boxplot() + 
    theme(axis.text.x=element_text(size=15, angle=90))

The x-axis labels are aligned by the center of the label. Is it possible to automatically align on the right so that every label would end right below the graph?

解决方案

Edit: A slightly nicer looking plot.

How about:

ggplot(d,aes(x=x,y=y)) + geom_boxplot() + 
   theme(axis.text.x=element_text(size=15, angle=90,hjust=0.95,vjust=0.2))

You can use the hjust and vjust parameters to move the labels around to where you want. Also if you wanted the axes labels right up against the x-axis, you can just change hjust = 1.

这篇关于将右侧的轴标签与ggplot2对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆