Professional Documents
Culture Documents
#conditional plot
histogram(~write | ses.f, hsb2)
#density plot
densityplot(~socst, hsb2)
#conditional plot
densityplot(~socst | ses.f, hsb2)
#Quantile-quantile plots
qqmath(~write, hsb2)
Q) Using iris dataset
library(lattice)
data("iris")
#Creating dataset
df<-iris
df
#Factoring
de$species.f = factor(de$species, labels=c("setosa", "versicolor", "virginica"))
de$SP.f = factor(de$SP, labels=c("Sepal", "Petal"))
#Scatterplot
xyplot(length~width | species.f, group=SP, data=de, layout=c(3,1),
main= "Scatterplot",
auto.key = list(title = "Structure", cex.title=1.2, space = "right"),
par.settings= list(
superpose.symbol = list(
pch = 21, cex = 1, col = c('#f8766d','#00bfc4'), fill= c('#f8766d','#00
bfc4')
)
),
xlab= "Width", ylab="Length"
)
#BoxPlot
bw_lattice <- bwplot(length ~ species | SP.f, data = de, main= "BoxPlot", xlab= "S
pecies", ylab="Length")
bw_theme <- trellis.par.get()
bw_theme$box.dot$cex <- 1
bw_theme$box.dot$pch <- "|"
bw_theme$box.rectangle$col <- "black"
bw_theme$box.rectangle$lwd <- 1
bw_theme$box.rectangle$fill <- "white"
bw_theme$box.umbrella$lty <- 1
bw_theme$box.umbrella$col <- "black"
bw_theme$plot.symbol$pch <- 16
bw_theme$plot.symbol$col <- "black"
bw_theme$strip.background$col <- "orange"
bw_theme$strip.title$col <- "orange"
update(bw_lattice, par.settings = bw_theme)
#violinplot
bwplot(
width ~ species | SP,
de,
panel = function
(...) {
panel.grid(-
1,-
1
)
panel.violin(...
)
},
par.settings = list(
strip.background = list(col="black"
)
),
col="white" )
#histogram
histogram(~length | SP*species, de, col="azure4", border = F, panel = function(...) {
panel.grid(-1,-1) panel.histogram(...) }, par.settings = list( strip.background = list(col="green") ))