
在不移动轴文本的情况下,轴周围有足够的空间:
library(ggplot)ggplot(mtcars,aes(mpg,wt)) + geom_point() + theme(axis.text.y = element_text(color = "red",margin = margin(40,40,40)))
但是,当头寸发生变化时,保证金不适用:
ggplot(mtcars,wt)) + geom_point() + scale_y_continuous(position = "right") + #This is the new line theme(axis.text.y = element_text(color = "red",40)))
无论axis.text是在右边还是左边,我都希望边距可以延续.难道我做错了什么?
解决方法 我相信这是因为右侧y轴标签的外观由theme()中的axis.text.y.right决定,虽然它继承自axis.text.y,但它只继承了未在axis.text.y.right本身.根据?theme中的细节,axis.text.y.right的继承链如下:
axis.text.y.right – > axis.text.y – > axis.text – >文本
ggplot中的默认主题是theme_grey.在控制台中输入theme_grey(最后没有()),您将看到完整的功能.我们来看看相关的位:
function(base_size = 11,base_family = "",base_line_size = base_size/22,base_rect_size = base_size/22) { half_line <- base_size/2 theme(text = element_text(family = base_family,face = "plain",colour = "black",size = base_size,lineheight = 0.9,hjust = 0.5,vjust = 0.5,angle = 0,margin = margin(),deBUG = FALSE),axis.text = element_text(size = rel(0.8),colour = "grey30"),axis.text.y = element_text(margin = margin(r = 0.8 * half_line/2),hjust = 1),axis.text.y.right = element_text(margin = margin(l = 0.8 * half_line/2),hjust = 0),... complete = TRUE)} ?element_text显示了element_text期望的完整参数列表:
element_text(family = NulL,face = NulL,colour = NulL,size = NulL,hjust = NulL,vjust = NulL,angle = NulL,lineheight = NulL,color = NulL,margin = NulL,deBUG = NulL,inherit.blank = FALSE)
鉴于所有的继承,axis.text.y.right在theme_grey中的实际参数是什么?
> family = base_family(来自文字)
> face =“plain”(来自文字)
> color =“grey30”(来自axis.text,它覆盖文本的“黑色”)
> size = base_size的80%(来自axis.text对文本的base_size的rel(0.8)修改)
> hjust = 0(来自axis.text.y.right,它覆盖了axis.text.y的1,它覆盖了文本的0.5)
> vjust = 0.5(来自文字)
> angle = 0(来自文字)
> lineheight = 0.9(来自文字)
> margin = margin(l = 0.8 * half_line / 2)(来自axis.text.y.right,它会覆盖axis.text.y的margin = margin(r = 0.8 * half_line / 2,它会覆盖文本的margin())
> deBUG = FALSE(来自文字)
> inherit.blank = FALSE(element_text的默认参数)
因此,给定一段代码如下,axis.text.y.right将继承color =“red”(它会覆盖axis.text的color =“grey30”).但由于它有自己的边距参数,它不会继承margin = margin(40,40):
ggplot(mtcars,wt)) + geom_point() + scale_y_continuous(position = "right") + theme(axis.text.y = element_text(color = "red",40)))
指定axis.text.y.right而不是axis.text.y可以解决这个问题:
ggplot(mtcars,wt)) + geom_point() + scale_y_continuous(position = "right") + theme(axis.text.y.right = element_text(color = "red",40)))总结
以上是内存溢出为你收集整理的`ggplot2` axis.text边距,修改了比例位置全部内容,希望文章能够帮你解决`ggplot2` axis.text边距,修改了比例位置所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)