简体   繁体   English

R Psych软件包:通过变量的多个直方图标签

[英]R Psych package: multi histogram labels by variable

I am ploting a multiple histogram for 5 variables, and I have the same title repeated along all of them. 我正在为5个变量绘制多个直方图,并且在所有变量上都重复了相同的标题。 I didn´t find a way to personalize it for each histogram. 我没有找到一种方法可以针对每个直方图进行个性化设置。 Is there a way to do it? 有办法吗? I am using the psych R package. 我正在使用psych R软件包。 Maybe another package to recommend? 也许另一个推荐的套餐?

The code line: 代码行:

multi.hist(AutosCompleteNorm[,11:15],main="bah")

And "bah" is repeated 5 times. 并且“ bah”重复5次。 I tried c("a","b",..."e") as an argument but it didn´t work. 我尝试了c(“ a”,“ b”,...“ e”)作为参数,但是没有用。

Package documentation: 包装文件:

https://www.rdocumentation.org/packages/psych/versions/1.8.3.3/topics/multi.hist https://www.rdocumentation.org/packages/psych/versions/1.8.3.3/topics/multi.hist

Thanks! 谢谢!

The current psych package doesn't seem to support this, which is strange because it would have been a natural feature for such a plot. 当前的psych软件包似乎并不支持此功能,这很奇怪,因为对于这样的情节来说,这自然是一个特性。

For customizability, I recommend you to take a look at ggplot and then layout in the format you wish using gridExtra . 为了实现可定制性,建议您先看一下ggplot ,然后使用gridExtra以所需的格式进行gridExtra

Here's the code to create the few histogram in ggplot : 这是在ggplot创建几个直方图的ggplot

library(ggplot2)
p1 <- ggplot(vids, aes(x=log(likes)))+geom_histogram()+labs(title="title1")
p2 <- ggplot(vids, aes(x=log(dislikes)))+geom_histogram()+labs(title="title2")
p3 <- ggplot(vids, 
aes(x=log(comment_count)))+geom_histogram()+labs(title="title3")

And then laying them up in a 2 row layout ( nrow=2 ): 然后将它们放置在2行布局中( nrow=2 ):

library(gridExtra)
grid.arrange(p1, p2, p3, nrow = 2)

在此处输入图片说明

Changing the layout to nrow=1 : 将布局更改为nrow=1 在此处输入图片说明

Following these comments, I just updated psych so that multi.hist is more useful. 根据这些评论,我刚刚更新了psych,以便multi.hist更有用。

You can now specify the margins for the plots, and it will, by default label each plot with the variable name. 现在,您可以指定图的边距,默认情况下,它将使用变量名称标记每个图。

I have not pushed the development version of psych (1.8.9) to CRAN yet, but it is available on my repository at 我尚未将psych(1.8.9)的开发版本推送到CRAN,但可以在我的存储库中找到它

install.packages("psych",repos="https://personality-project.org/r",type="source")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM