[英]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的情況下執行此操作?
無需在此處重塑數據。
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.