简体   繁体   English

R - 从格子改变 bwplot 上的箱线图

[英]R - change of boxplot on bwplot from lattice

I was tasked to change the code which uses graphics package into something with bwplot from lattice package with the same result.我的任务是将使用图形 package 的代码更改为来自lattice package 的bwplot代码,结果相同。

Boxplot:箱形图:

par(mai = c(1, 1, 1, 1), omi = c(0, 0, 0, 0))
set.seed(591)
xx1 <- rnorm(20, mean = 3, sd = 3.6)
xx2 <- rpois(40, lambda = 3.5)
xx3 <- rchisq(31, df = 5, ncp = 0)
box1 <- boxplot(xx1, xx2, xx3, names = c("Group-1", "Group-2", "Group-3"), cex = 0.7)

Unfortunately, when I'm trying to change it, I can't insert these 3 plots in 1 chart.不幸的是,当我尝试更改它时,我无法将这 3 个图插入 1 个图表中。 All I have done so far:到目前为止我所做的一切:

library(lattice)
bwplot(xx1,ylab="Group-1")
bwplot(xx2,ylab="Group-2")
bwplot(xx3,ylab="Group-3")

You can use following code to do it using lattice package您可以使用以下代码使用lattice package

library(dplyr)
df1 <- data.frame(xx1, levels ="Group-1")
df2 <- data.frame(xx2, levels ="Group-2")
df3 <- data.frame(xx3, levels ="Group-3")
colnames(df1) <- c("Data","Group")
colnames(df2) <- c("Data","Group")
colnames(df3) <- c("Data","Group")

df <- bind_rows(df1,df2,df3)

bwplot(Data~Group,df)

在此处输入图像描述

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

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