我有以下数据集。
> ds
dataset_clustering.CODICE_DOMANDA FAT_AZI_MLN IMPORTO_PROGETTO NUM_ADDETTI Modelli Formazione
22870 22870 4.855849e-03 0.25386313 0.001403368 0 0
22893 22893 3.606493e-04 0.40618102 0.115209837 0 0
16258 16258 4.433197e-04 0.58254746 0.140670944 0 0
14684 14684 6.189941e-04 0.35717439 0.304330393 0 0
12873 12873 2.480110e-05 0.65121413 0.022654370 0 0
12933 12933 2.603806e-02 0.02551876 0.017107725 0 1
12047 12047 7.130316e-05 0.20094923 0.005012029 0 0
22880 22880 1.963420e-05 0.16556291 0.015503876 0 0
11479 11479 2.856260e-03 0.57615894 0.786688051 0 1
20836 20836 3.089804e-04 0.20640177 0.004611067 0 0
Investimento Sostituzione CAMPANIA COSTRUZIONI ESITO
22870 1 0 1 1 B
22893 1 0 1 1 R
16258 1 0 1 1 P
14684 1 0 1 1 P
12873 1 0 1 1 B
12933 0 0 1 1 B
12047 1 0 1 1 R
22880 1 0 1 1 B
11479 0 0 1 1 P
20836 1 0 1 1 B
我想训练一个群集该数据集的SOM:
# Train a SOM
grid_type<-'hexagonal' # 'rectangular'
library(kohonen)
num_rows <- 3
num_cols <- 3
r_length <- 100 # 100 1000 10000 100000
tpsom<-paste(grid_type," (",num_rows,"x",num_cols,")")
set.seed(13)
#-------------------------------------------------------------------
somres <- som(as.matrix(ds[,2:length(colnames(ds))-1]),
grid=somgrid(ydim=num_rows,xdim=num_cols,grid_type),
rlen = r_length # default = 100
)
# Create a plot of the som
png("Example.png")
par(mar=c(5.1,4.1,6.1,2.1))
plot(somres,
type = "counts",
#main=paste("Analisi SOM - ","Numero di input per cella","\n")
main=paste("Analisi SOM\n","Numero di input per cella","\n",
"Mappa: ",tpsom
)
)
dev.off()
我不喜欢它如何自动设置颜色,因为它似乎违反直觉。我想设置五种颜色,从白色开始变为浅红色,正常红色,深红色,深红色。否则,至少要反转图中的颜色。
我不能使用参数palette.name = etc等。
我该如何修改颜色?如果我使用ggplot,我会松开我绘制som的属性type = "counts"
。