Search code examples
rlatticegraphic

Change the graphic using the lattice package


I have a graphic built using the package Graphics. Please, help to change it using the package lattice.

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)

I was trying, but it doesn't work.

library(lattice)
set.seed(591)
type <- sample(c("Group-1", "Group-2", "Group-3"), n, replace = TRUE)
xx1 <- rnorm(20, mean = 3, sd = 3.6)
xx2 <- rpois(40, lambda = 3.5)
xx3 <- rchisq(31, df = 5, ncp = 0)
df <- data.frame(xx1, xx2, xx3)
bwplot(xx1,xx2,xx3,data=df)

enter image description here Thank you in advance.


Solution

  • set.seed(591)
    xx1 <- rnorm(20, mean = 3, sd = 3.6)
    xx2 <- rpois(40, lambda = 3.5)
    xx3 <- rchisq(31, df = 5, ncp = 0)
    df <- data.frame(xx = c(xx1,xx2,xx3), 
                     type=c(rep(1,length(xx1)),rep(2,length(xx2)),rep(3,length(xx3))) )
    df$type <- factor(df$type, labels=c("Group-1", "Group-2", "Group-3"))
    
    library(lattice)
    bwplot(xx~type, data=df)
    

    enter image description here