我试图在同一个面板中的数据框中绘制一些变量的多个直方图。 以下是一些代码:
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 NULLNo 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更多推荐
发布评论