在同一面板中绘制多个直方图(Plotting multiple histograms in same panel)

系统教程 行业动态 更新时间:2024-06-14 17:01:34
在同一面板中绘制多个直方图(Plotting multiple histograms in same panel)

我试图在同一个面板中的数据框中绘制一些变量的多个直方图。 以下是一些代码:

library(lattice) dd <- data.frame(gp = factor(rep(paste('Group', 1:6, sep = ''), each = 100)), x = rnorm(600)) histogram( ~ x | gp, data = dd) histogram( ~ x | gp, data = dd, as.table = TRUE)

这是将数据x放入组1到6中。在给定的数据帧中,我们已经有特定类别的数字。 例如,假设我想在同一个面板中绘制身高,体重和平均血压(日期框架中的变量)的直方图。 如何在不必形成新数据集和组1到3的情况下执行此操作?

I am trying to plot multiple histograms of some variables in a data frame in the same panel. Here is some following code:

library(lattice) dd <- data.frame(gp = factor(rep(paste('Group', 1:6, sep = ''), each = 100)), x = rnorm(600)) histogram( ~ x | gp, data = dd) histogram( ~ x | gp, data = dd, as.table = TRUE)

This is putting the data x into the groups 1 to 6. In a given dataframe, we already have the numbers in particular categories. For example, suppose I want to plot a histogram of height, weight and average blood pressure (variables in a date frame) in the same panel. How would I do this without having to form a new data set and groups 1 to 3?

最满意答案

无需在此处重塑数据。

histogram( ~ height +age +weight ,data = dd)

然后,您可以使用layout来更改面板的显示顺序。 例如:

histogram( ~ height +age +weight ,layout=c(1,3),data = dd)

这将在3个面板中产生3个直方图。

编辑

要添加标题,您可以使用main

histogram( ~ height +age +weight ,layout=c(1,3),data = dd, main='PLEASE READ LATTICE HELP')

附注:设置参数在不同的晶格函数之间共享。 例如,xlab的条目: See xyplot 。 当你去xyplot帮助你可以阅读:

main: Typically a character string or expression describing the main title to be placed on top of each page. Defaults to NULL

No need to reshape data here.

histogram( ~ height +age +weight ,data = dd)

You can then ply with layout to change the display order of panels. For example:

histogram( ~ height +age +weight ,layout=c(1,3),data = dd)

This will produce 3 histograms in 3 panels.

EDIT

to add a title you can use main

histogram( ~ height +age +weight ,layout=c(1,3),data = dd, main='PLEASE READ LATTICE HELP')

Side note: Settings parameters are shared between different lattice functions. For example the entry of xlab: See xyplot. when you go to xyplot help you can read :

main: Typically a character string or expression describing the main title to be placed on top of each page. Defaults to NULL

更多推荐

本文发布于:2023-04-20 18:39:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/a3d0ffa8126d6b348d99e5ae2a37f765.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:直方图   多个   面板   在同一   histograms

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!