我有一张表,其中包含不同的绘图类型和它们排序的簇号。该表如下所示:
'data.frame': 80 obs. of 16 variables:
$ GS_CT_HC_NO: Factor w/ 16 levels "GS_CT_HC_NO",..: 1 1 1 1 1 2 2 2 2 2 ...
$ CT_HC_NO : Factor w/ 8 levels "CT_HC_NO","CT_HC_SW",..: 1 1 1 1 1 2 2 2 2 2 ...
$ GS_CT_HC : Factor w/ 8 levels "GS_CT_HC","GS_CT_LC",..: 1 1 1 1 1 1 1 1 1 1 ...
$ GS_HC_NO : Factor w/ 8 levels "GS_HC_NO","GS_HC_SW",..: 1 1 1 1 1 2 2 2 2 2 ...
$ GS_CT_NO : Factor w/ 8 levels "GS_CT_NO","GS_CT_SW",..: 1 1 1 1 1 2 2 2 2 2 ...
$ CT_HC : Factor w/ 4 levels "CT_HC","CT_LC",..: 1 1 1 1 1 1 1 1 1 1 ...
$ CT_NO : Factor w/ 4 levels "CT_NO","CT_SW",..: 1 1 1 1 1 2 2 2 2 2 ...
$ GS_CT : Factor w/ 4 levels "GS_CT","GS_FT",..: 1 1 1 1 1 1 1 1 1 1 ...
$ GS_HC : Factor w/ 4 levels "GS_HC","GS_LC",..: 1 1 1 1 1 1 1 1 1 1 ...
$ GS_NO : Factor w/ 4 levels "GS_NO","GS_SW",..: 1 1 1 1 1 2 2 2 2 2 ...
$ HC_NO : Factor w/ 4 levels "HC_NO","HC_SW",..: 1 1 1 1 1 2 2 2 2 2 ...
$ NO : Factor w/ 2 levels "NO","SW": 1 1 1 1 1 2 2 2 2 2 ...
$ HC : Factor w/ 2 levels "HC","LC": 1 1 1 1 1 1 1 1 1 1 ...
$ GS : Factor w/ 2 levels "GS","SS": 1 1 1 1 1 1 1 1 1 1 ...
$ CT : Factor w/ 2 levels "CT","FT": 1 1 1 1 1 1 1 1 1 1 ...
$ ClusterNr : int 4 5 2 4 1 4 3 3 4 4 ...
现在,我使用 GS_CT_HC_NO(第一列)的 R 中的 vcd 包和具有以下代码的 Cluster Nr 创建了一个马赛克图:
mosaic(ClusterNr ~ GS_CT_HC_NO, data = groups, shade = TRUE, highlighting_fill =
terrain.colors(5), labeling_args = list(tl_labels = FALSE, clip = FALSE, tl_varnames = TRUE,
pos_labels = "center", set_varnames = c(GS_CT_HC_NO = "Plot Class", ClusterNr = "Cluster"),
rot_labels = c(0, 0, 0, 90), gp_labels = (gpar(fontsize = 8)), just_labels = "left"))
我想通过使用 for 循环为所有其他绘图类型组合创建这样一个图,但是当我尝试使用
for(j in 1:dim(groups[,-16])[2]) {
mosaic(ClusterNr ~ j, data = groups, shade = TRUE, highlighting_fill =
terrain.colors(5), labeling_args = list(tl_labels = FALSE, clip = FALSE, tl_varnames =TRUE,
pos_labels = "center", set_varnames = c(j = "Plot Class", ClusterNr = "Cluster"),
rot_labels = c(0, 0, 0, 90), gp_labels = (gpar(fontsize = 8)), just_labels = "left"))
}
我收到错误:
Error in model.frame.default(formula = ~j + ClusterNr, data = groups) :
Variablenlängen sind unterschiedlich (gefunden für 'ClusterNr')
错误代码的最后一部分意味着变量的长度不同(特别是对于变量'ClusterNr')
有人能帮我找到一个正确的工作循环,并有可能将每个情节保存为 jpeg 吗?
干杯,斯文!