我有一个数据集(mydata),其中一部分如下:
'data.frame': 36190 obs. of 16 variables:
$ RE : int 38 41 11 67 30 18 38 41 41 30 ...
$ LU : int 4200 3330 530 4500 3000 1790 4700 3400
$ COUNTRY : Factor w/ 4 levels "DE","FR","JP", "FR"…
$Light : Factor w/2 levels "ON","OFF","ON", ….
$OR : Factor w/2 levels "S","T","S",….
$PAT : Factor w/3 levels "low", "high", "middle",….
现在我想为所有可能的情况绘制RE vs LU,例如一个图(COUNTRY = FR,Light = off,OR = S,PAT = low)和一个(COUNTRY = FR,Light = on) ,OR = S,PAT =高)一个用于(COUNTRY = FR,Light = off,OR = S,PAT = high),依此类推。我创建了一个像下面这样的数据框,但我不知道如何循环遍历这个数据框并使用ggplot2生成所有图表
mydata <- data.frame( RE = sample( 5:50, 100, TRUE), LU = sample(1500:4500, 100 ), COUNTRY = factor( sample( c( "DE","FR","JP","AU"), 100, TRUE)),Light=factor( sample( c( "ON", "OFF" ), 100, TRUE)), OR = factor( sample( c( "S", "T" ), 100, TRUE)), PAT = factor( sample( c( "low", "high", "middle" ),100,TRUE)))
感谢您的帮助。