I have changed a little bit my R code that worked perfectly,but instead 3 now I have 7 clusters.
layout(matrix(c(1, 1, 2, 2, 3, 3, 4, 4, 5), ncol=1))
# main plots
par(mai=rep(0.5, 4))
fcm <-c(14.0,14.1,13.0,14.2,14.7,13.8,14.0)
gk <-c(12.1,12.5,12.2,12.0,11.5,12.0,11.4)
gg <-c(14.0,14.1,13.3,12.8,12.0,12.2,12.0)
data1 <- rbind(fcm,gk,gg)
colnames(data1) <- c(6,7,8,9,10,11,12)
fcm <-c(2.65,2.55,2.4,2.45,2.45,2.5,2.45)
gk <-c(2.45,2.55,2.4,2.3,2.2,2.35,2.1)
gg <-c(2.6,2.65,2.5,2.35,2.4,2.4,2.2)
data2 <- rbind(fcm,gk,gg)
colnames(data2) <- c(6,7,8,9,10,11,12)
fcm <-c(8.8,6.5,6.6,8.2,8.0,8.4,9.0)
gk <-c(12.7,11.0,11.1,10.5,10.7,10.0,9.5)
gg <-c(2.1,2.1,1.8,2.0,2.0,1.9,1.8)
data3 <- rbind(fcm,gk,gg)
colnames(data3) <- c(6,7,8,9,10,11,12)
fcm <-c(0.47,0.53,0.45,0.39,0.40,0.47,0.48)
gk <-c(0.45,0.51,0.34,0.40,0.42,0.42,0.44)
data4 <- rbind(fcm,gk)
colnames(data4) <- c(6,7,8,9,10,11,12)
barplot(as.matrix(data1),ylim=c(0,20),main="P wave",
xlab="number of clusters", ylab="traveltime rms(ms)",
col=c("red", "black", "green"), beside=TRUE)
barplot(as.matrix(data2),ylim=c(0,2),main="MT",
xlab="number of clusters", ylab="MT functions",
col=c("red", "black", "green"), beside=TRUE)
barplot(as.matrix(data3),ylim=c(0,20),main="XBI",
xlab="number of clusters", ylab="index value",
col=c("red", "black", "green"), beside=TRUE)
barplot(as.matrix(data4),ylim=c(0,0.6),main="NCE",
xlab="number of clusters", ylab="index value",
col=c("red", "black"), beside=TRUE)
par(mai=c(0,0,0,0))
plot.new()
legend(legend = c("fcm","gk","gg"), fill = c( "red", "black", "green"),
"center", horiz=TRUE)
But then I got
Error in `colnames<-`(`*tmp*`, value = c(6, 7, 8, 9, 10, 11, 12)) :
length of 'dimnames' [2] not equal to array extent
The problem is with the rbind.I am combining 3 vectors,each of them has 7 elements.What should I change?I want that each element has the proper number of clusters labeled behind.
You need to supply one more column name. Your data has eight columns, as can be seen, e.g., with
> length(fcm)
[1] 8
or
> ncol(data1)
[1] 8
or by displaying the matrix:
> data1
# [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
#fcm 14.0 14.1 13.0 14 2.0 14.7 13.8 14.0
#gk 12.1 12.5 12.2 12 0.0 11.5 12.0 11.4
#gg 14.0 14.1 13.0 3 12.8 12.0 12.2 12.0
while
> length( c(6, 7, 8, 9, 10, 11, 12))
[1] 7
You could try with
colnames(data1) <- c(6:13)
With your data, this would be:
fcm <-c(14.0,14.1,13.0,14,2,14.7,13.8,14.0)
gk <-c(12.1,12.5,12.2,12,0,11.5,12.0,11.4)
gg <-c(14.0,14.1,13,3,12.8,12.0,12.2,12.0)
data1 <- rbind(fcm,gk,gg)
colnames(data1) <- c(6:13)
which gives:
> data1
6 7 8 9 10 11 12 13
fcm 14.0 14.1 13.0 14 2.0 14.7 13.8 14.0
gk 12.1 12.5 12.2 12 0.0 11.5 12.0 11.4
gg 14.0 14.1 13.0 3 12.8 12.0 12.2 12.0
without any error message.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With