簡體   English   中英

R:按因子拆分指標圖形直方圖

[英]R: Split metricsgraphics histogram by factor

我有一個看起來像以下數據幀:

'data.frame':   400 obs. of  4 variables:
 $ admit: Factor w/ 2 levels "rejected","accepted": 1 2 2 2 1 2 2 1 2 1 ...
 $ gpa  : num  3.61 3.67 4 3.19 2.93 3 2.98 3.08 3.39 3.92 ...

現在,我想使用metricsgraphics軟件包將其轉換為GPA的直方圖,但將數據除以“允許”因子。 怎么做?

使用ggplot,我可以執行以下操作:

ggplot(data, aes(gpa)) + 
geom_histogram(aes(fill=admit, y=..density..),
           position="dodge",
           binwidth=0.1
          )

但我正在研究如何使用metricsgraphics具體做到這一點。 我目前有

mjs_plot(data, x = gpa) %>%
     mjs_histogram(bins = 80)

但這當然不會被因素分解。

我認為您必須制作每個圖並將其排列成網格。 從小插圖包裝中

moar_plots <- lapply(1:7, function(x) {
  mjs_plot(rbeta(10000, x, x), width="250px", height="250px", linked=TRUE) %>%
    mjs_histogram(bar_margin=2) %>%
    mjs_labs(x_label=sprintf("Plot %d", x))
})

mjs_grid(moar_plots, nrow=4, ncol=3, widths=c(rep(0.33, 3)))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM