什么是“父元素” ggplot2的? [英] What is "parent element" of ggplot2?
问题描述
R
, ggplot2
问题。
< code $ ggplot2 :: rel()说明
rel()用于指定大小相对于父母而言。
究竟是什么父母?例如,我很乐意将我的剧情标题的大小设置为 rel(5)
。我的标题宽度究竟是多少?
我注意到有两个单位,我认为它们在ggplot2中用作相关大小, .PT
。我认为 rel()
和 .pt
之间有一些关系。 .pt
等于 2.845276
。为什么??和2.845276什么?像素?
父母定义在 help(theme)
。请注意,文档中所说的大多数参数如何继承自......。这是面向对象的编程。
例如, axis.text
是轴的父元素.text.x
:
library(ggplot2)
library(gridExtra)$ b (x,y))+ geom_point()
p2 <-p1 + theme(axis.text.x = element_text(size = rel(2)))
p3< - p2 + theme(axis.text = element_text(size = 5))
grid.arrange(p1,p2,p3,ncol = 1)
R
, ggplot2
question.
?ggplot2::rel()
says
rel() is used to specify sizes relative to the parent.
What is the "parent" exactly? For example, I'd love to set the size of my plot title to rel(5)
. What is the width of my title in inches exactly?
I noticed there are two "units" that I believe somehow are used as a relevant size in ggplot2, .pt
. I think there is some relation between rel()
and .pt
. .pt
equals to 2.845276
. Why?? And 2.845276 of what? Pixels?
The parents are defined in help("theme")
. Note how for most arguments the documentation says "inherits from ...". This is object oriented programming.
E.g., axis.text
is the parent of axis.text.x
:
library(ggplot2)
library(gridExtra)
DF <- data.frame(x = 1, y = 2)
p1 <- ggplot(DF, aes(x, y)) + geom_point()
p2 <- p1 + theme(axis.text.x = element_text(size = rel(2)))
p3 <- p2 + theme(axis.text = element_text(size = 5))
grid.arrange(p1, p2, p3, ncol = 1)
这篇关于什么是“父元素” ggplot2的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!