在ggplot2中相当于cex [英] cex equivalent in ggplot2
问题描述
在我的工作中,我经常使用散点图来显示散点图文本标签。这意味着一个 plot()
命令,其后是 text()
。我使用 cex
来快速调整字体大小以达到我想要的效果。
我创建了一个文本散点图快速使用 qplot
。但我无法快速调整大小。这是一个愚蠢的代码示例:
pre $ $ $ $ $ $ data $ $ $ $ $ $ $ $ $ $ qplot(Income,Population,data = as.data。 frame(state.x77),geom = c(smooth,text),method =lm,label = state.abb)
在过去我会这样做:
plot(xlim = range (Income),ylim = range(Population),data = state.x77,type =n)
text(Income,Population,state.abb,data = state.x77,cex = .5)
如果我想将文本大小从默认值中减去一半(哦,我必须手动进行线性回归并添加abline()以获得回归线 - 很好,通过ggplot2完成所有操作。)
我知道我可以添加一个尺寸大小调整,但它不是像我习惯的相对大小调整。哈德利啾啾地说,尺寸是用毫米来衡量的,这对我来说并不完全直观。由于我经常调整剧情的大小,无论是在R还是在LaTeX中,绝对比例对我来说都没有那么有用。
我必须错过一些非常简单的事情。这是什么?
哦 - 我知道我还没有真正使用过强大的ggplot2命令 - 只是想先弄个简单的东西。 p>
我认为您正在调整文本本身的大小,而不是x轴,对吗? b
$ b
以下是使用 ggplot()
命令的一种方法。
ggplot(data = as.data.frame(state.x77),aes(x = Income,y = Population))+
geom_smooth(method =lm,se = FALSE) +
geom_text(aes(label = state.abb),size = 2.5)
I've finally started to get into Hadley Wickham's impressive ggplot2 package, and am working my way through his book.
In my work, I frequently display scatterplots using text labels. That's meant a plot()
command, followed by text()
. I used cex
to adjust to font size to what I wanted it very quickly.
I created a text scatterplot very quickly using qplot
. But I can't adjust the size fast. Here's a silly code example:
data(state)
qplot(Income,Population,data=as.data.frame(state.x77),geom=c("smooth","text"),method="lm",label=state.abb)
Whereas in the old days I'd do:
plot(xlim=range(Income),ylim=range(Population),data=state.x77,type="n")
text(Income,Population,state.abb,data=state.x77, cex=.5)
If I wanted the text size halved from what I saw at the defaults (oh, and I'd have to do a linear regression manually and add abline() to get the regression line -- nice to do it all in one via ggplot2).
I know I can add a size adjustment with size, but it's not a relative size adjustment like I'm used to. Hadley tweeted me to say that size is measured in mm, which isn't fully intuitive to me. Since I often adjust the size of the plot, either in R or in LaTeX, an absolute scale isn't as useful to me.
I must be missing something really simple. What is it?
Oh -- and I know I havn't really used the powerful ggplot2 commands yet -- just wanted to get the simple stuff down first.
I think you are tyring to adjust the size of the text itself, not the x-axis, right?
Here's an approach using the ggplot()
command.
ggplot(data = as.data.frame(state.x77), aes(x = Income, y = Population)) +
geom_smooth(method = "lm", se = FALSE) +
geom_text(aes(label = state.abb), size = 2.5)
这篇关于在ggplot2中相当于cex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!