How to draw a rectangle under the plot lines in plot? - r

This is my graph:
which I did using the following dataset:
targ_plot = structure(c(4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25,
4.25, 4.25, 3.75, 3.75, 3.75, 3.5, 3.5, 3.5, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3.25, 3.25, 3.25, 3.5, 3.5, 3.5, 3.75, 3.75, 4, 4, 4.25,
4.25, 4.5, 4.5, 4.5, 4.75, 4.75, 4.75, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5.25, 5.25, 5.25, 4.25, 3.75, 3, 3, 3, 2.5, 2.25,
1.75, 1.75, 1.75, 1.75, 1.75, 1.75, 1.75, 1.75, 1.75, 1.75, 1.75,
1.75, 1.75, 1.75, 1.75, 1.75, 1.75, 1.75, 1.75, 1.75, 1.75, 1.75,
1.75, 2, 2, 2, 2.25, 2.25, 2.25, 2.25, 2, 1.75, 1.75, 1.75, 1.75,
1.75, 1.75, 1.75, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5,
1.5, 1, 1, 1, 1, 1, 1, 0.75, 0.75, 0.75, 0.75, 0.75, 0.75, 0.75,
0.4, 0.4, 0.4, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3,
0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.25, 0.25, 0.25, 0.25,
0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 3.25,
3.25, 3.25, 3.25, 3.25, 3.25, 3.25, 3.25, 3.25, 3.25, 3.25, 2.75,
2.75, 2.75, 2.5, 2.5, 2.5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2.25, 2.25,
2.25, 2.5, 2.5, 2.5, 2.75, 2.75, 3, 3, 3.25, 3.25, 3.5, 3.5,
3.5, 3.75, 3.75, 3.75, 4, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25,
4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 3.75, 3.25,
2.5, 2, 2, 1.5, 1.25, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.25, 1.25, 1.25, 1.5, 1.5, 1.5,
1.5, 1.25, 1, 1, 1, 1, 1, 1, 1, 0.75, 0.75, 0.75, 0.75, 0.75,
0.75, 0.75, 0.75, 0.75, 0.75, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.25,
0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.15, 0.15, 0.15, 0.05, 0.05,
0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05,
0.05, 0.05, 0.05, 0.05, 0.05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2.25, 2.25, 2.25,
2.25, 2.25, 2.25, 2.25, 2.25, 2.25, 2.25, 2.25, 1.75, 1.75, 1.75,
1.5, 1.5, 1.5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.25, 1.25, 1.25, 1.5,
1.5, 1.5, 1.75, 1.75, 2, 2, 2.25, 2.25, 2.5, 2.5, 2.5, 2.75,
2.75, 2.75, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3.25, 3.25,
3.25, 3.25, 2.75, 2, 1, 1, 0.5, 0.25, 0.25, 0.25, 0.25, 0.25,
0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.5, 0.5, 0.5,
0.75, 0.75, 0.75, 0.75, 0.5, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
0.25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, -0.1, -0.1, -0.1, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2,
-0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.2, -0.3, -0.3,
-0.3, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4,
-0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4,
-0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4,
-0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.4, -0.5,
-0.5, -0.5, -0.5, -0.5, 0.499999999999989, 1.24999999999997,
-0.250000000000039, 0, 0.999999999999979, -2, 0, 1.25000000000002,
-0.249999999999995, 2.99999999999998, 8.65, -5.14999999999999,
0.499999999999989, 2.4, 8.44999999999998, 2.99999999999998, 0.950000000000006,
-4.49999999999999, 0.124999999999998, 0, 0.550000000000006, 0.499999999999989,
0, 0, 0.499999999999989, 0.299999999999967, 2.50000000000001,
3.55000000000001, 0.249999999999995, -0.249999999999995, 0, -0.100000000000033,
0.300000000000011, -0.100000000000033, -0.200000000000022, -1.2,
-0.100000000000033, -0.699999999999967, 0, -0.649999999999995,
0, 0.800000000000001, 0, 0, 0, 0, -1.00000000000002, -0.800000000000001,
-0.200000000000022, -1.2, 0.200000000000022, -0.599999999999978,
-2.49999999999999, -0.550000000000006, -1.75000000000001, 0.424999999999986,
0, -0.099999999999989, -0.999999999999979, 0.4, -0.099999999999989,
-0.800000000000001, 0.099999999999989, 0.150000000000006, 0,
-0.100000000000033, 0.150000000000006, -0.350000000000072, -1.49999999999997,
-1.18499999999999, -0.300000000000011, 0.349999999999984, -0.0999999999999446,
0.349999999999984, -0.0500000000000611, 0, -0.100000000000033,
-0.100000000000033, -1.14999999999998, 0, -0.300000000000011,
2.4, -2.6, 2.59999999999998, -6.30000000000002, 0.349999999999984,
3.95, 4.6, -0.900000000000001, 1.35000000000001, 2.3, 0.2, -0.45,
0, -0.5, -0.750000000000001, -0.35, 0, -0.1, -0.25, 0.1, 1.6,
0.4, 0.2, 0.35, 0.3, 0, -0.2, 0.0500000000000056, 0.350000000000006,
-0.0499999999999945, 0.99999999999999, -0.700000000000012, 0,
0.299999999999989, 0.600000000000001, 2.5, 12.2, -14.3, 2.8,
0.1, 0.35, 0.499999999999995, -0.2, 0.3, 1.8, -10.4, 0.700000000000001,
0.85, 0.550000000000001, 0.599999999999999, 0, 0.1, 0, 0.1, 0.1,
-0.2, 0.399999999999999, 0.1, 0, 0, 0, -0.3, 0.45, 0, 0.550000000000001,
0.999999999999998, 0.899999999999998, 2.1, 0.499999999999999,
0, -0.1, -0.8, 0, 0.4, -0.35, 0.505, 0, -1.3, 1.175, 0, 0, -0.0399999999999998,
0, 0.0150000000000011, 0, 0, 5.03, 0.88, 0, 2.405, 0, 0, 0, 0.4,
0, 0.344999999999995, 0, 0, 0, 0, 0, 0, 0, 0, 0, -0.0849992036819458,
0, 0, 0, 0, 0.964999198913574, 0, 0, 0, 0, 0, -0.455000996589661,
0, 0, 0, 0.549998879432678, 0, -0.510001182556152, 0, 0, 0, 0.499999523162842,
0, 0.499999523162842, 3.41, 0, 3.440002, -0.06, 0, 0.024998,
0.009999), .Dim = c(217L, 4L), .Dimnames = list(NULL, c("MLF",
"MRO", "DFR", "Target")), .Tsp = c(2002, 2020, 12), class = c("mts",
"ts", "matrix"))
colors = c("#00366C", "#909800" , "#79ABE2", "#E16A86")
and this is the code that produced the graph above:
plot(targ_plot, plot.type = "single", ylab = "" , xlab = "" , main = "Target", col = colors, lwd = 2, xaxt = "n")
axis(1, at = seq(2002, 2020, 1), labels = seq(2002, 2020, 1))
legend("bottomright", colnames(targ_plot), col = colors, lwd = 3, bty = "n")
abline(h = 0, col = "black", lty = 2)
rect(2008,16,2009,-17, col= rgb(0,0,1, alpha=0.5), border = FALSE)
As you can see the rectangle is above the lines, I want it to be below the lines and to be gray possibly. I have been looking for similar things everywhere. I couldn't solve the problem.
Can you help me sort this out?
Thanks

Steps:
Create a blank plotting region by plot(..., type = "n").
Draw the rectangle.
Set the graphical parameter new by par(new = T).
Run your plotting code.
Reset graphical parameters.
# (1)
plot(targ_plot, type = "n", plot.type = "single", ylab = "", xlab = "", main = "Target", col = colors, lwd = 2, xaxt = "n")
# (2)
rect(2008, 16, 2009, -17, col = gray(0.5, alpha = 0.5), border = FALSE)
# (3)
op <- par(new = T)
# (4)
plot(targ_plot, plot.type = "single", ylab = "", xlab = "", main = "Target", col = colors, lwd = 2, xaxt = "n")
axis(1, at = seq(2002, 2020, 1), labels = seq(2002, 2020, 1))
legend("bottomright", colnames(targ_plot), col = colors, lwd = 3, bty = "n")
abline(h = 0, col = "black", lty = 2)
# (5)
par(op)

Related

is there a simple way to draw a graph in christmas tree farm in r

Is there a mathematical function or a way in which we can get a graph that will be in the form of a Christmas tree, like this?
thanks for your help
Here's one of many options:
tree <- data.frame(x = c(-5, 5, 2, 4, 1.5, 3, 0, -3, -1.5, -4, -2, -5,
-0.75, 0.75, 0.75, -0.75),
y = c(1, 1, 3, 3, 5, 5, 7, 5, 5, 3, 3, 1, 0, 0, 1, 1),
part = rep(c("branches", "trunk"), times = c(12, 4)))
baubles <- data.frame(x = c(-1.9, -2.4, 0.5, -0.3, -0.2, -1.3, 0.5,
1.2, -2.2, -1, 1.7, -1.4, -1.4, 0.4, 2.1, 0.4,
-0.8, -3.3, 0.5, -2.2, -0.1, -1.5, 2, 3.9, 1.3,
-1.7, 3.7, 2.8, 1, -0.1, 3.8, -2.9, -1.9, -1.7,
-2.6, -2.3, 0.9, 1, -0.4, 1.5, 1.8, -0.5, -1.4,
-0.4, -0.5, -0.9, -1.7, 0.7, 1.6, 1.2, -0.4, 1,
0.8, 2.3, -2.5, -2, -2.9, -1.4, -1.1, 0.2),
y = c(3, 3.3, 1.2, 4.4, 5.1, 5.2, 1.1, 6, 1.5, 2.4, 1.2,
5.4, 2.2, 3.4, 3.4, 3.8, 3.1, 1.2, 4.3,
1.6, 2.4, 5.4, 4.5, 1.1, 1.3, 5, 1.5, 1.9, 1.7,
5.4, 1.3, 1.1, 2.2, 4, 1.8, 2, 4.6, 1.1, 5.9, 4.4,
2, 1.5, 2, 1.2, 5.3, 3.6, 3.5, 4.5, 5.8, 3, 2.7,
5.3, 3.1, 1.7, 1.6, 2.8, 3.6, 2.2, 2.8, 1.7),
color = sample(c("white", "yellow", "red"), 60, TRUE))
library(ggplot2)
ggplot(tree, aes(x, y)) +
geom_polygon(aes(fill = part)) +
geom_point(data = baubles, aes(color = color), size = 4) +
scale_fill_manual(values = c("green4", "brown4"), name = "Parts of tree") +
scale_color_identity(guide = guide_legend(), labels = c("red bauble",
"white bauble", "yellow bauble"), name = "Decorations") +
theme_minimal(base_size = 20)
Created on 2022-11-20 with reprex v2.0.2

Coarsened Exact Matching with cem package- Error in .subset2(x, i, exact = exact)

I'm trying to perform coarsened exact matching on the following data.
> dput(head(cem_data))
structure(list(sex = c(1, 1, 1, 2, 2, 2), age = c(40, 59, 53,
60, 49, 60), edlev = c(3, 3, 3, 2, 3, 3), sw = c(44, 17, 10,
41, 26, 23), sw2 = c(15, 1, 5, 34, 5, 6), som = c(2.14, 0.14,
1.86, 3, 1.71, 2.14), som_2 = c(0.71, 0.14, 2, 2.57, 1.71, 2.14
), ap = c(3.5, 1.5, 1.33, 3.33, 2.67, 2.17), ap_2 = c(3, 0.17,
2.33, 3, 0.83, 1.67), dep = c(2.83, 0.17, 0.33, 2.83, 2.17, 2.33
), dep_2 = c(1.17, 0, 0.33, 2.33, 0.83, 1), int = c(2.86, 1.43,
1, 2, 2.29, 2.14), int_2 = c(2.29, 0.57, 0.14, 2.57, 1.71, 1.43
), pho = c(3.2, 0, 0, 3.4, 0.8, 0.4), pho_2 = c(1.6, 0, 0, 3.2,
0, 0.4), psy_b = c(2.67, 0.11, 0.83, 3.06, 1.61, 1.72), psy_b_2 = c(1.11,
0.06, 0.89, 2.67, 0.94, 1.28), s_wirk = c(4, 2.2, 1.6, 3.2, 1.4,
2.2), s_wirk_2 = c(2.8, 0.8, 1.8, 2.6, 1.6, 1.4), soz_b = c(2.75,
1.5, 1, 2.25, 1.25, 1.5), soz_b_2 = c(2.75, 1, 1, 2.25, 1.5,
1.25), soz_u = c(0.75, 0.75, 1.75, 3.25, 1, 3.25), soz_u_2 = c(1,
0.25, 1.75, 2.5, 2.5, 2), wohl = c(3.6, 1.4, 1.8, 3.4, 3, 3),
wohl_2 = c(2, 0.6, 1.4, 2.8, 2.2, 1.2), au_bei_aufn = c(1,
1, 1, 1, 1, 1), age_reha = c(40.9890410958904, 59.3945205479452,
53.372602739726, 60.2, 49.3342465753425, 60.7534246575342
), group_format = c(0, 0, 0, 0, 0, 0)), row.names = c(6L,
7L, 10L, 15L, 20L, 29L), class = "data.frame")
With the following code:
require(cem)
voll_data <- voll_data %>%
select(-c("auf_nr", "icd_10_1", "icd_10_2", "icd_10_3", "icd_10_4","icd_10_5", "bdi_date", "aufnahme", "entlassung")) %>%
mutate_if(is.factor,as.numeric) %>%
mutate_if(is.character, as.numeric)
cem_data <- data.frame(na.omit(voll_data))
#cem_data_s <- scale(cem_data[,5:26])
#cem_data <- cbind.data.frame(cem_data[, 1:4], cem_data_s, cem_data[, 27:36])
variables <- c("age", "sex", "edlev", "sw","au_bei_aufn")
ungleich2 <- imbalance(cem_data$group_format, data=cem_data)
However, following error is being shown, when calculating the "matt".
Error in .subset2(x, i, exact = exact) : attempt to select less than one element in get1index
7.
(function(x, i, exact) if (is.matrix(i)) as.matrix(x)[[i]] else .subset2(x, i, exact = exact))(x, ..., exact = exact)
6.
[[.data.frame(data, treatment)
5.
data[[treatment]]
4.
is.factor(x)
3.
as.factor(data[[treatment]])
2.
cem.main(treatment = treatment, data = data, cutpoints = cutpoints, drop = drop, k2k = k2k, method = method, mpower = mpower, verbose = verbose, baseline.group = baseline.group, keep.all = keep.all)
1.
cem(treatment = cem_data$group_format, data = cem_data, drop = "sw2", cutpoints = list(age = agecut), grouping = list(edlev_gr))
# automated coarsening
matt <- cem(cem_data$group_format, data = cem_data, drop= "sw2")
print(matt)
Does anyone have an idea what am I doing wrong?
Thanks a lot!!

Somers D differences between R and SAS and within R

I am new to both R and SAS. I want to calculate somers D, following the logistic regression.my dataframe(vac1) is combination of Titer and Protection.
> vac1=structure(list(Titer = c(0.9, 0.9, 0.9, 1.51, 0.9, 0.9, 2.86,1.95,2.71, 2.56, 2.71, 3.01, 2.71, 2.41, 2.11, 1.95, 2.26, 2.71, 2.56, 2.41, 2.56, 1.95, 1.81, 2.26, 2.11, 1.81, 1.95, 1.95, 1.34, 2.56, 2.26, 2.26, 2.11, 2.41, 2.71, 2.56, 1.65, 1.95, 1.51, 1.95,1.81, 1.81, 1.81, 1.95, 2.11, 2.86,2.41, 1.95, 2.56, 2.71, 2.71,2.41, 1.81, 2.41, 1.65, 1.81, 2.11, 2.11, 1.81, 1.81,2.26, 2.41,1.65, 2.56, 2.71, 2.11, 1.81), Protection = c(0, 0, 0, 0, 0,0, 1, 0, 1, 1,1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1,0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0)), .Names = c("Titer","Protection"), row.names = c(NA, -67L), class = "data.frame").
my logistic regression formula is.
> logit=glm(Protection~Titer, data=vac1, family=binomial(link="logit")).
the resulting predicted probalities from logit model is combined with original Protection data from vac1 dataframe and created vac4 dataframe.
> vac4=cbind(vac1$Protection,logit$fit)
> colnames(vac4)=c("Protection","PredictedProb").
calculated somers D by 2 ways.
1.using InformationValue package
>library(InformationValue)
>somersD(actuals=vac4$Protection, predictedScores=vac4$PredictedProb
I got the value 0.733.
2.using function copied from a link
http://shashiasrblog.blogspot.in/2014/02/binary-logistic-regression-fast.html
OptimisedConc=function(logit)
{
Data = vac4
ones = Data[Data[,1] == 1,]
zeros = Data[Data[,1] == 0,]
conc=matrix(0, dim(zeros)[1], dim(ones)[1])
disc=matrix(0, dim(zeros)[1], dim(ones)[1])
ties=matrix(0, dim(zeros)[1], dim(ones)[1])
for (j in 1:dim(zeros)[1])
{
for (i in 1:dim(ones)[1])
{
if (ones[i,2]>zeros[j,2])
{conc[j,i]=1}
else if (ones[i,2]<zeros[j,2])
{disc[j,i]=1}
else if (ones[i,2]==zeros[j,2])
{ties[j,i]=1}
}
}
Pairs=dim(zeros)[1]*dim(ones)[1]
PercentConcordance=(sum(conc)/Pairs)*100
PercentDiscordance=(sum(disc)/Pairs)*100
PercentTied=(sum(ties)/Pairs)*100
N<-length(logit$fit)
gamma<-(sum(conc)-sum(disc))/Pairs
Somers_D<-(sum(conc)-sum(disc))/(Pairs-sum(ties))
k_tau_a<-2*(sum(conc)-sum(disc))/(N*(N-1))
return(list("Percent Concordance"=PercentConcordance,
"Percent Discordance"=PercentDiscordance,
"Percent Tied"=PercentTied,
"Pairs"=Pairs,
"Gamma"=gamma,
"Somers D"=Somers_D,
"Kendall's Tau A"=k_tau_a))
}
OptimisedConc(logit).
Here i am getting the gamma and somers D values but are reversed compared to what i got it in SAS and the somers D value calculated by 2nd method in R and SAS is different from what i obtained it using the InformationValue package of R. similarly kendalls tau is infinite showing in R and in SAS it is 0.38.
can anyone help where i am making mistake? thanking you.

Scale is not shown on y-axis of plot

I am using the leaps package to generate the following plots:
> library(leaps)
>
>
> dput(datSel)
structure(list(oenb_dependent = c(1.0227039, -5.0683144, 0.6657713,
3.3161374, -2.1586704, -0.7833623, -0.2203209, 2.416144, -1.7625406,
-0.1565037, -7.9803936, 9.4594715, -4.8104584, 8.4827107, -6.1895262,
1.4288595, 1.4896459, -0.4198522, -5.1583964, 5.2502294, 1.0567102,
-1.0923342, -1.5852298, 0.6061936, -0.3752335, 2.5008664, -1.3999729,
2.2802166, -2.1468756, -1.4890328, -0.79254376, 3.21804705, -0.94407886,
-0.27802316, -0.20753079, -1.12610048, 2.0883735, -0.7424854,
0.44203729, -1.48905938, 1.39644424, -3.8917377, 11.25665848,
-9.22884035, 3.26856762, -0.00179541, -2.39664325, 4.00455574,
-5.60891295, 4.6556348, -4.40536951, 6.64234497, -7.34787319,
7.56303006, -8.23083674, 4.43247855, 1.31090412), gdp = c(-271.6,
-284.2, 34.3, -206, -253.1, -116.8, -169.9, -63.6, -174.2, -138.2,
-171.2, -198.2, -126.2, -222.5, -8.2, -172.5, -169.1, -207.5,
-114.6, -182.4, -43.7, 43.5, 166, 293.1, -30, -144.6, 16.9, -115.6,
-147.4, -189.1, -166.8, -157.9, -108.7, -150.9, -267.3, -176.2,
-231.3, -160.4, -251.5, -194.5, -186.3, -193, -171.6, -191.7,
-254.4, -140.6, -126.3, -66.7, -102.3, -100.4, -133.1, -61.8,
-1.1, -130.3, -35.8, -114.9, -79.1), employ = c(0.2237, -0.024,
0.0906, 0.2809, 0.0555, -0.2404, 0.1717, -0.1225, 0.0538, -0.1211,
-0.2819, 0.2998, -0.2625, -0.0808, 0.2338, -0.3807, -0.2774,
-0.0124, -0.2158, -0.1496, 0.0765, 0.2548, 0.2935, -0.129, 0.3021,
-0.2781, -0.4863, -0.0464, -0.5377, -0.0671, -0.5776, -0.1231,
-0.4383, -0.4593, -0.3337, -0.0388, -0.4048, -0.0609, -0.4173,
-0.1218, -0.1554, -0.1477, 2.4688, 0.1383, 0.1927, -0.1106, -0.1791,
-0.154, 0.1666, -0.0767, -0.3145, -0.1784, 0.2428, -0.0614, 0.0611,
-0.0804, 0.1366), atx = c(296.910157, 22.96997, 22.719932, -18.090049,
-304.469971, 128.03003, 49.19999, -311.47001, -114.390014, 183.710083,
-267.380059, 56.169976, 818.880004, 115.449952, 65.060068, -405.610117,
-262.829834, 355.199951, -138.44, 141.720029, -538.630127, -402.029907,
54.210005, 1016.93001, 1175.389892, -177.23999, 747.070088, 14.319805,
341.959961, -223.759766, -182.03, -595.19998, -122.550049, 394.110107,
-472.800078, -209.580049, -407.540039, -417.01001, -201.519902,
-388.510005, -53.469971, -122.640014, -321.61001, -193.259985,
-46.180054, -142.599976, -13.059985, -79.840039, 172.859985,
46.090054, -148.8, -56.290054, 122.75, -20.279907, -113.240039,
87.860034, -31.580078), un.employ = c(-0.0946, 0.0285, -0.1297,
-0.0563, -0.2938, 0.2474, -0.386, 0.1812, -0.2538, -0.4493, 0.4135,
-0.7771, 0.4232, 0.2375, -0.2525, 0.3409, 0.1633, -0.0739, 0.4948,
0.3698, -0.4075, -0.7342, -0.2505, -0.3096, -0.3006, 0.3804,
0.3246, 0.4871, 0.1521, -0.3552, 0.22, 0.0585, 0.2905, 0.1454,
0.2726, 0.0472, -0.0215, -0.6432, 0.4422, 0.0229, -0.0864, -0.35,
-0.7569, -0.2062, 0.0867, -0.1833, -0.2003, -0.0546, -0.1151,
0.3641, -0.3421, -0.1825, -0.023, -0.2115, -0.0344, 0.0293, -0.0332
), carReg = c(0.73435946, 0.24001161, 16.90532537, -14.60281976,
6.47603166, -8.35815849, 3.55576685, 7.10705794, -4.6955223,
10.9623709, 5.5801857, -6.4499936, -9.46196502, 9.36289122, -8.52630424,
5.45070994, -4.5346405, -2.26716538, 2.56870398, 0.013737, 5.7750101,
-27.1060826, 1.08977179, 4.94934712, 17.55391859, -13.91160577,
10.38981128, -11.81349246, -0.0831467, 2.79748237, 1.84865463,
-1.98736934, -6.24191695, 13.33602659, -3.86527871, 0.78720993,
4.73360651, -4.1674034, 9.37426802, -5.90660464, -0.4915792,
-5.84811629, 9.67648643, -6.96872719, -7.6535767, 0.24847595,
0.18685263, -2.28766949, 1.1544631, -3.87636933, -2.4731545,
4.33876671, 1.08836339, 5.64525271, 1.90743854, -3.94709355,
-0.84611324), cpi = c(1.16, -3.26, 0.22, -3.51, 0.84, -2.81,
-0.34, -4.57, -0.12, -3.95, -1.37, -2.73, 0.35, -5.38, -4.43,
-3.08, 0.74, -3.03, -1.09, -2, 0.35, -1.52, 1.28, 0.2, -0.25,
-4.55, -2.49, -4.24, -0.31, -2.96, -2.24, -0.46, -0.06, -2.67,
-1.27, -1.4, -0.7, -0.96, -2.18, -2.53, -0.52, -1.74, -2.18,
-1.4, -0.34, -0.09, -1.65, -1.15, -0.17, -2.01, -1.38, -1.24,
0.09, -2.44, -1.92, -2.61, -0.34), prodPrice = c(0.3, 0.8, 1.4,
0.5, 0, 2.3, 1, -0.1, 0.1, -0.4, -1.1, -0.4, -0.1, -3.9, -4.5,
-1.74, -3.48, -5.84, -1.92, 0.19, -1.1, 3.56, 3.57, 2.28, -4.11,
-3.01, -3.67, -1.74, -1.63, -2.02, -2.74, -0.73, -1.74, -3.19,
-1.56, -0.64, 1.36, 0.55, -5.38, -2.11, -3.37, -2.02, -1.74,
-0.01, 1.02, 1.73, -1.82, 0.36, 0.18, -0.64, 1.29, 2.1, 0.82,
-0.09, 1.83, -1.83, -2.83), productionConstr = c(0.7000584, 3.900325,
0.4000333, 1.0000834, -4.6003834, -6.50054172, 7.00058342, 3.2002667,
-4.6003834, 1.1000917, 1.3001083, -5.5004584, 2.3001917, -2.2001833,
-3.60030006, 2.70022502, 3.20026664, -2.0001666, 2.340195, 0.8700725,
0.8700725, 0.2900242, -1.740145, 0.6800566, -1.4501208, 9.8508209,
-6.5705476, -1.2501041, 2.8002333, 1.2501042, -1.3501125, -1.0600884,
-4.9304108, -3.28027339, 4.15034589, -4.34036172, 0.87007251,
-9.85082091, 3.81031753, 2.70022502, -3.96033003, -3.86032169,
2.12017668, -1.93016085, -0.3900325, 3.58029836, -12.66105509,
2.03016918, -0.3900325, -2.22018502, -0.0900075, 0.87007251,
-0.78006501, -0.67005584, 7.44062006, -6.48054005, -1.25010417
), constrPriceIndex = c(-0.3, -0.3, -1.42e-14, 0.2, 0.5, -0.7,
0.3, -0.1, 0.3, -0.9, -0.1, 0.8, -0.2, -0.2, -0.3, 0.2, -0.1,
-0.1, -0.16686, 0.41673, -0.08334, 0.16669, 0.25004, -0.33339,
-0.41673, -0.50009, 0.25004, 0.83348, -0.08335, -0.08334, -0.3334,
0.33339, 1e-05, 0.08334, -0.08335, 0.41674, 0.16669, -0.16669,
-0.13514, 0.15617, 1e-05, -0.46855, 0.15619, 0.54662, 0, -0.23426,
0.07808, 0.07809, 0.15618, -0.31236, 0.0781, 0.31235, -0.15618,
-0.23427, 0.07809, 1e-05, -0.0781), constrCostTotal = c(-0.5,
-0.7, -0.1, -0.06667, -0.16667, -0.6, -0.83333, -0.2, -0.33333,
-1, -1.06667, 0.16667, -0.36667, -0.23333, -1.18893, -0.30742,
-0.05589, -1.92836, -1.0061, -0.25153, -0.67073, -0.02795, 0.0559,
1.62094, -1.62094, -2.51526, -2.06809, 0.02795, -0.16769, -1.45325,
-1.14584, -0.41921, -1.64889, -1.87246, -1.03405, -0.67073, 0.11179,
-0.13974, -0.36695, -0.61157, -0.51373, -1.73687, -1.49225, -0.44033,
-0.48926, -0.88067, -0.6605, -0.04893, -0.12231, -0.83175, -0.34248,
0.1957, -0.12231, -0.78282, -0.29355, -0.44034, -0.39141), primConstTot = c(-0.33334,
-0.93333, -0.16667, -0.33333, -0.16667, -0.86666, -0.3, -0.4,
-0.26667, -1.56667, -0.73333, 0.1, -0.23333, -0.26667, -1.5774,
-0.19284, 0.38568, -2.42423, -0.93663, 0.08265, -0.63361, 0.0551,
-0.49587, 2.39668, -1.70798, -3.36085, -2.56196, 0.16529, 0,
-1.84572, -1.3774, -0.49586, -1.70798, -1.90081, -0.55096, -0.77134,
-0.16529, -0.30303, -0.17066, -0.23853, -0.64401, -1.52657, -1.57426,
-0.28623, -0.54861, -1.07336, -0.71558, 0.02385, -0.38164, -1.09721,
0, 0.14311, -0.38164, -1.02566, -0.42934, -0.35779, -0.4532),
baumeisterarbeit = c(-177L, -499L, -88L, -176L, -91L, -460L,
-160L, -213L, -142L, -835L, -391L, 54L, -125L, -143L, -831L,
-102L, 205L, -1291L, -501L, 45L, -338L, 30L, -264L, 1278L,
-911L, -1791L, -1365L, 87L, -9L, -974L, -734L, -264L, -910L,
-1013L, -317L, -382L, -102L, -165L, -89L, -127L, -344L, -812L,
-840L, -151L, -293L, -572L, -381L, 12L, -203L, -584L, -1L,
77L, -204L, -546L, -207L, -205L, -248L), gesamtbaukost = c(-274L,
-384L, -55L, -38L, -90L, -329L, -457L, -110L, -183L, -547L,
-586L, 92L, -202L, -127L, -676L, -168L, -30L, -1057L, -552L,
-138L, -368L, -15L, 32L, 887L, -888L, -1379L, -1134L, 16L,
-92L, -800L, -625L, -261L, -949L, -950L, -559L, -348L, 54L,
-93L, -214L, -336L, -282L, -953L, -816L, -242L, -268L, -483L,
-362L, -27L, -66L, -456L, -189L, 108L, -68L, -429L, -156L,
-235L, -225L), lohn = c(66831L, 66966L, 68594L, 69408L, 69408L,
69408L, 70858L, 71583L, 71583L, 71583L, 73167L, 73959L, 73959L,
73959L, 74575L, 74883L, 74883L, 74883L, 75983L, 76533L, 76533L,
76749L, 78321L, 79107L, 79107L, 79107L, 80423L, 81081L, 81081L,
81081L, 83007L, 83970L, 83970L, 83970L, 85794L, 86706L, 86706L,
86706L, 87566L, 87996L, 87996L, 87978L, 88270L, 88416L, 88416L,
88503L, 90779L, 91917L, 91917L, 91917L, 93727L, 94632L, 94632L,
94632L, 96090L, 96819L, 96819L), resProp.Dwell = c(0.8, -4,
-3.2, 2.7, -1.6, -1, -2.4, -0.4, -0.8, 1, -12.1, 0.2, -5.2,
3.7, -2.7, -1.7, 1.5, 0.7, -7.9, 0.3, 0.3, 1.4, -3.3, -1,
-1.6, 1.5, 0.5, 1.5, -1, -2.2, -3.5, 0.5, 0.5, -0.9, -0.4,
-3.4, 0.9, 0.1, -0.2, -2.8, -0.8, -6.2, 11.3, -4.6, 1, 1.1,
-1.7, 4.1, -5, 2.3, -2.3, 4.6, -6.3, 6.3, -6.9, 0, 2.4),
resProp.Dwell.1 = c(-0.4, -7.5, -1, -2.4, 0, 1.2, 0.7, -4.3,
0, 3.3, -18.3, 11.2, -4.9, 4.9, -0.3, -1.8, 2.7, 0.9, -10.8,
-2.6, 6.1, -0.1, -6.3, 1.2, 0.8, 4.1, -3.5, 4.6, -0.2, -2.7,
-15, 8, -0.1, -0.1, 0.4, -4.9, 0.5, 2.7, -2.5, 1.9, -4.6,
-1, 8.1, -4.5, 0.3, 0.7, 2.2, -0.5, -3.8, 1.8, -4.7, 5.9,
-2, 2.3, -0.4, -1.4, 2.3), resProp.Dwell.2 = c(1.3, -2.5,
-4.2, 5, -2.3, -1.9, -3.7, 1.2, -1.2, 0.1, -9.6, -4.4, -5.4,
3.2, -3.8, -1.5, 0.9, 0.7, -6.7, 1.5, -2.2, 2, -2, -1.8,
-2.7, 0.3, 2.3, 0.1, -1.2, -2.1, 1.5, -2.7, 0.7, -1.3, -0.7,
-2.7, 1, -1, 0.9, -4.9, 0.9, -8.5, 12.7, -4.7, 1.4, 1.2,
-3.4, 6.1, -5.4, 2.4, -1.2, 4, -8.1, 7.9, -9.6, 0.6, 2.4),
resProp.Dwell.3 = c(1.4, -2.5, -5.1, 3.6, -3, -3, -2.6, 1.5,
-1.3, -0.3, -9.2, -6, -6.6, 3, -4.4, -1.2, 1.1, 0.5, -7.1,
1.3, -1.3, 1.7, -1.6, -2.8, -3.5, 0.8, 2.9, 0, -0.3, -2.7,
2.3, -3.3, 1.8, -2, 0.4, -3.8, 1.1, -1.5, 1.3, -5.6, 2.2,
-9.7, 14.3, -5.7, 1.4, 1, -3.6, 7.3, -6.5, 3.1, -2.4, 4.2,
-7.9, 8.3, -10.2, 0.2, 3.6), resProp.Dwell.4 = c(0.9, -2.9,
2.7, 13.7, 3, 5.6, -12, -0.5, -0.2, 2.5, -12, 6.7, 3.1, 4.7,
0.2, -3.6, -0.6, 1.8, -3.6, 2.6, -8.2, 3.8, -4.5, 4.7, 3.4,
-3.4, -1.6, 1.1, -8.5, 2.4, -3.8, 1.4, -7.1, 3.4, -7.5, 4.3,
0.3, 1.9, -1.8, 0.7, -8.5, -0.7, 2.5, 2, 1.4, 2.7, -2.2,
-2, 1.7, -2.2, 6.9, 2.7, -8.8, 4.4, -5.4, 3.8, -5.7), cbre.indu.primeRent = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.05, 0.05, 0, 0.1, 0, 0.1,
0, 0.1, 0.05, 0, 0.05, 0.1, 0.1, 0, -0.25, -0.25, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.09, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0), cbre.office.Capital.Value....m.. = c(-64.516129,
-133.83665, -67.861143, -128.947368, -64.43299, -63.11803,
-122.44898, -178.217822, -57.076296, -114.220445, -169.716206,
-52.197802, -57.142858, 0, -114.285714, -257.142857, -189.189189,
-42.953668, -42.193426, -41.453191, 11.441648, 232.919255,
198.701298, 687.160263, -3.906674, -126.31579, -126.315789,
-126.31579, -126.315789, -126.31579, -126.315789, -52.631579,
0, 0, 0, 0, 0, 0, -200, 0, 0, 0, 0, 0, 0, 0, -160, 0, 93.714286,
0, 0, 0, 0, 0, 0, 0, 0), cbre.office.PrimeRent = c(-0.25,
-0.25, 0, -0.25, 0, 0, -0.25, -0.25, 0, -0.25, -0.5, 0, -0.25,
0, -0.5, -0.5, -0.25, 0, 0, 0, 0.25, 0.5, 0.5, 0, -0.5, -0.5,
-0.5, -0.5, -0.5, -0.5, -0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0.3, 0, 0.41, 0, 0, 0, 0, 0, 0, 0, 0),
cbre.office.primeYield = c(0, 0, 0.15, 0.15, 0.2, 0.2, 0.2,
0.25, 0.25, 0.25, 0.25, 0.2, 0.15, 0.1, 0.05, 0.15, 0.3,
0.35, 0.4, 0.3, 0.2, 0, -0.15, -0.85, -1, -0.85, -0.75, -0.1,
0, 0, 0, 0.05, 0.05, 0.05, 0.05, 0, 0, 0, 0.2, 0.2, 0.2,
0.2, 0, 0, 0, 0, 0.25, 0.25, 0.25, 0.25, 0, 0, 0, 0, 0, 0,
0), cbre.retail.primeRent = c(0, 0, -5, -5, -2, -3, -4, -4,
-2, -1, 0, 0, -1, -1, -1, -3, -5, -5, -5, -5.5, -5, -5, -5,
-7.5, -8, -11, -13, -10, -9, -6, -4, -2, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, -0.33, -0.33, -0.33, -0.33, 0, 0,
0, 0, -7.26, -7.26, -7.26), cbre.retail.primeYield = c(5.25,
5.2, 5.25, 5.3, 5.35, 5.4, 5.4, 5.4, 5.45, 5.5, 5.5, 5.6,
5.65, 5.7, 5.85, 5.95, 6, 6.1, 6.2, 6.25, 6.25, 6, 5.75,
5.25, 5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.75, 4.8, 4.8, 5,
5, 5, 5, 5, 5, 5.25, 5.25, 5.75, 5.75, 5.75, 5.75, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6), cbre.retail.capitalValue = c(-1882.35294,
230.76923, -230.76923, -226.41509, -670.78117, -436.13707,
-222.22223, 0, -205.91233, -202.16847, 0, -393.5065, -403.91909,
-186.30647, -539.81107, -748.11463, -764.70588, -311.47541,
-301.42782, -627.09677, -480, 720, 782.6087, 645.96273, 251.42857,
1386.66667, -533.33334, -533.33333, -533.33333, 0, 0, -1024.56141,
-192.10526, 0, -730, 0, 0, 0, 0, 0, -834.28571, 0, -1450.93168,
0, 0, 0, -700.78261, 0, 0, 0, 0, 0, 0, 0, -1452, 0, 0)), .Names = c("oenb_dependent",
"gdp", "employ", "atx", "un.employ", "carReg", "cpi", "prodPrice",
"productionConstr", "constrPriceIndex", "constrCostTotal", "primConstTot",
"baumeisterarbeit", "gesamtbaukost", "lohn", "resProp.Dwell",
"resProp.Dwell.1", "resProp.Dwell.2", "resProp.Dwell.3", "resProp.Dwell.4",
"cbre.indu.primeRent", "cbre.office.Capital.Value....m..", "cbre.office.PrimeRent",
"cbre.office.primeYield", "cbre.retail.primeRent", "cbre.retail.primeYield",
"cbre.retail.capitalValue"), row.names = c(NA, -57L), class = "data.frame")
> leaps=regsubsets(datSel$oenb_dependent~.,
+ data=datSel, nbest=10)
> plot(leaps, scale="adjr2")
As you can see the text on the y-axis cannot be read. Any suggestions, how to change my plot that the numbers can be read?
I appreciate your replies!
The problem is in the leaps:::plot.regsubsets function that gets called when you plot the regsubsets object.
Line 30 is:
axis(2, at = 1:nmodels, labels = signif(yscale[index], 2))
Aside from modifying the source of the package there is not much to do.
A quick way is to use
fixInNamespace(plot.regsubsets, ns = "leaps")
And edit the function, for instance changing the line above to:
num.labs <- 10
at <- seq(1, nmodels, length.out = num.labs)
lab <- signif(yscale[index], 2)
lab <- lab[seq(1, length(lab), length.out = num.labs)]
axis(2, at = at, labels = lab)

xyplot not merging plots when more than two conditioning variables

When I run the following code, xyplot produces 4 separate plots 2 by 3 plots,
whereas I want a single 4 by 6 trellis (to save real estate
space on the axis anotation and legends).
Note that my problem is different from this one in that I don't want to
see four set of axis/legends.
Here is some example data:
B <- structure(list(yval = c(0.88, 4.31, 7.52, 3.21, 3.27, 4.93, 4.21,
0.7, 0.68, 0.92, 3.86, 5.67, 9.08, 1.95, 3.27, 1.44, 2.38, 0.85,
0.79, 0.55, 0.79, 10.52, 0.9, 4, 0.78, 2.46, 0.78, 1.64, 2.47,
0.77, 0.83, 0.86, 3.65, 8.25, 0.65, 0.88, 0.95, 4.05, 4.98, 1.43,
4.43, 2.94, 5.52, 0.9, 3.69, 0.79, 0.74, 1.49, 7.29, 0.58, 8.47,
5.82, 0.84, 0.87, 0.69, 1.38, 0.83, 2.32, 0.86, 7.32, 6.73, 6.7,
3.3, 1.58, 2.74, 0.88, 4.2, 3.79, 4.98, 2.54, 1.84, 1.2, 2.59,
11.99, 0.78, 0.92, 0.59, 3.83, 0.92, 2.6, 0.95, 3.18, 2.75, 9.83,
9.81, 0.55, 0.83, 6.29, 1.64, 1.12, 0.65, 3.96, 4.27, 3.99, 20,
0.83, 6.23, 6.81, 0.86, 0.7), xval = c(0.62, 0.81, 9.01, 3.72,
1.49, 3.92, 6.22, 6.64, 5.56, 6.64, 4, 7.36, 9.6, 1, 1.64, 3.34,
3.47, 3.37, 4.34, 6.63, 7.62, 4.07, 5.69, 3.76, 9.74, 1.58, 1.53,
2.62, 1.64, 1.18, 9.79, 9.9, 2.76, 7.96, 5.11, 4.74, 9.92, 0.49,
9.05, 8.59, 0.7, 5.8, 5.34, 3.14, 6.96, 2.05, 8.29, 0.35, 7.52,
6.56, 2.01, 7.92, 3.89, 6.31, 8.64, 6.18, 4.49, 0.63, 7.52, 7.82,
1.25, 9.54, 4.68, 0.4, 1.38, 8.7, 4.71, 8.27, 5.72, 0.75, 6.08,
0.11, 1.38, 0.37, 4.94, 0.53, 7.53, 3.11, 2.73, 4.93, 9.47, 2.18,
4.54, 7.12, 8.28, 6.62, 5.14, 4.42, 0.21, 9.52, 3.77, 6.43, 6.78,
6.87, 9.47, 6.42, 0.81, 8.88, 7.2, 8.68), gval = c(1, 2, 5, 5,
2, 1, 2, 1, 2, 3, 6, 5, 1, 3, 2, 3, 5, 2, 6, 4, 4, 1, 1, 6, 4,
2, 1, 2, 4, 5, 5, 3, 6, 5, 4, 2, 2, 3, 3, 6, 2, 4, 1, 4, 4, 1,
1, 2, 2, 5, 1, 1, 2, 2, 1, 3, 1, 5, 6, 5, 1, 5, 4, 4, 3, 6, 6,
4, 5, 4, 4, 6, 5, 6, 5, 2, 1, 1, 6, 6, 2, 5, 5, 1, 1, 4, 6, 3,
4, 6, 3, 5, 3, 3, 6, 2, 1, 5, 1, 3), type = c(5, 2, 1, 5, 1,
1, 1, 1, 2, 12, 5, 1, 2, 5, 5, 12, 12, 12, 12, 2, 12, 2, 12,
5, 12, 2, 12, 12, 5, 12, 12, 12, 5, 2, 5, 12, 1, 1, 1, 1, 2,
12, 1, 12, 2, 12, 2, 2, 1, 1, 2, 1, 5, 12, 12, 5, 12, 5, 5, 1,
1, 1, 2, 5, 5, 5, 5, 5, 1, 5, 12, 12, 5, 2, 12, 12, 1, 1, 5,
5, 5, 2, 5, 1, 2, 2, 5, 1, 5, 2, 5, 5, 5, 2, 2, 5, 1, 2, 2, 5
), cr = c(0.2, 0.4, 0.4, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.4, 0.4,
0.4, 0.4, 0.2, 0.4, 0.4, 0.4, 0.2, 0.2, 0.2, 0.2, 0.4, 0.4, 0.4,
0.2, 0.2, 0.2, 0.4, 0.2, 0.2, 0.4, 0.4, 0.4, 0.4, 0.2, 0.4, 0.2,
0.4, 0.2, 0.2, 0.4, 0.4, 0.2, 0.2, 0.4, 0.2, 0.2, 0.2, 0.4, 0.2,
0.4, 0.2, 0.2, 0.4, 0.4, 0.2, 0.2, 0.4, 0.2, 0.4, 0.4, 0.4, 0.4,
0.2, 0.4, 0.4, 0.4, 0.4, 0.2, 0.4, 0.4, 0.2, 0.4, 0.4, 0.2, 0.2,
0.2, 0.2, 0.2, 0.4, 0.4, 0.4, 0.2, 0.4, 0.4, 0.2, 0.2, 0.4, 0.4,
0.2, 0.2, 0.2, 0.4, 0.2, 0.4, 0.4, 0.4, 0.4, 0.2, 0.2), p = c(4,
12, 12, 8, 12, 8, 12, 4, 4, 8, 8, 4, 4, 8, 8, 8, 4, 12, 8, 4,
12, 12, 12, 12, 8, 12, 4, 4, 8, 8, 8, 4, 8, 12, 4, 12, 12, 4,
12, 8, 4, 4, 12, 4, 4, 8, 4, 4, 8, 4, 8, 12, 12, 8, 4, 8, 8,
8, 8, 12, 4, 8, 4, 12, 4, 4, 12, 4, 12, 12, 8, 4, 4, 12, 8, 12,
4, 4, 12, 4, 8, 4, 8, 12, 8, 4, 4, 4, 8, 4, 4, 12, 8, 12, 8,
4, 4, 8, 8, 4), nsamp = c(100, 300, 300, 200, 300, 200, 300,
100, 100, 200, 200, 100, 100, 200, 200, 200, 100, 300, 200, 100,
300, 300, 300, 300, 200, 300, 100, 100, 200, 200, 200, 100, 200,
300, 100, 300, 300, 100, 300, 200, 100, 100, 300, 100, 100, 200,
100, 100, 200, 100, 200, 300, 300, 200, 100, 200, 200, 200, 200,
300, 100, 200, 100, 300, 100, 100, 300, 100, 300, 300, 200, 100,
100, 300, 200, 300, 100, 100, 300, 100, 200, 100, 200, 300, 200,
100, 100, 100, 200, 100, 100, 300, 200, 300, 200, 100, 100, 200,
200, 100)), .Names = c("yval", "xval", "gval", "type", "cr",
"p", "nsamp"), row.names = c(NA, -100L), class = "data.frame")
And here is the code I am running:
library(lattice)
library(latticeExtra)
library(grid)
types<-rep(NA,6)
types[1]<-expression(paste(epsilon,"=",0.2,", p=",4,sep=""))
types[2]<-expression(paste(epsilon,"=",0.2,", p=",8,sep=""))
types[3]<-expression(paste(epsilon,"=",0.2,", p=",12,sep=""))
types[4]<-expression(paste(epsilon,"=",0.4,", p=",4,sep=""))
types[5]<-expression(paste(epsilon,"=",0.4,", p=",8,sep=""))
types[6]<-expression(paste(epsilon,"=",0.4,", p=",12,sep=""))
types<-rep(types,4)
cl<-rainbow(7)[-4]
xyplot(B$yval~B$xval|as.factor(B$p)*as.factor(B$cr)*as.factor(B$type),
group=B$gval, as.table=TRUE,
ylab=expression(kappa(Sigma,S)), col=cl, xlab=expression(nu),
xlim=c(0,10), ylim=c(0,10), type=c("l","g"), lwd=5, cex.lab=2,
strip=function(...){
panel.fill(trellis.par.get("strip.background")$col[1])
type <- types[panel.number()]
grid::grid.text(label=type,x=0.5,y=0.5,gp=gpar(fontsize=20))
grid::grid.rect()
},
key=list(text=list(c("A","B","C","D","E","F"),cex=2),
lines=list(type=rep("l",6), label.cex=2,col=cl,lwd=3),columns=3),
par.settings=list(par.xlab.text=list(cex=2),axis.text=list(cex=2),
par.ylab.text=list(cex=2)))
Three conditioning variables means that it makes a three dimensional grid of panels, where the third dimension is onto multiple pages. One alternative is to only condition on two variables; here I use : to make the first conditioning factor the intersection of the first two original conditioning factors.
xyplot(B$yval~B$xval|as.factor(B$p):as.factor(B$cr)*as.factor(B$type), ...
I think you want layout=c(6,4) somewhere in your call to xyplot. Once you do that you will have to reconfigure many other settings.

Resources