@SimonO10 highlights the problem in your code, but beyond that, have you considered ggplot? It's really designed to do this type of stuff easily. The main problem you'll run into is you need to convert your data to long format. But once you've done that the plotting is almost trivial:
# Use ggplot to plot
ggplot(
subset(data, L1==1), # just use `data` here if you want all plots
aes(x=height, y=weight, color=paste(L1, L2, sep="-"))
) + geom_point() + scale_color_discrete(name="id-sub.id") + scale_y_reverse()
with facet_wrap
if you want stuff to show up in different graphs (note the data changed b/c I didn't set the random seed):
ggplot(
subset(data, L1==1), # just use `data` here if you want all plots
aes(x=height, y=weight, color=paste(L1, L2, sep="-"))
) + geom_point() + scale_color_discrete(name="id-sub.id") +
facet_wrap( ~ L2)
In order to get your data into long format, I started with some data in your structure (see end of post for how I did it):
data
# [[1]]
# [[1]]$`1`
# height weight
# 1 0.79199970 0.19434040
# 2 0.83137244 0.41325506
# ...
#
# [[1]]$`2`
# height weight
# 1 0.099096870 0.64563244
# 2 0.736456033 0.06103266
# ...
#
# [[2]]
# [[2]]$`1`
# height weight
# 1 0.2622071 0.176313366
# 2 0.5747873 0.887846513
# ...
then converted to long format as @baptiste suggested (note numbers don't match exactly b/c I regenerated random data)
# Convert to long format
library(reshape2)
data <- melt(data, id.vars=c("height", "weight"))
# height weight L2 L1
# 1 0.55637070 0.50990818 1 1
# 2 0.59839293 0.91242349 1 1
# ...
# 11 0.39170638 0.86185414 2 1
# 12 0.69356092 0.03145715 2 1
# ...
# 21 0.67580737 0.55668117 1 2
# 22 0.01335459 0.29615540 1 2
# ...
and the code to generate data:
data <-
replicate(5, simplify=F,
replicate(2, simplify=F,
data.frame(height=runif(10), weight=runif(10))
) )
data <- lapply( data, function(x) { names(x) <- seq_along(x); x } )