Error in contrasts, supervised classification - r

I was trying to follow this tutorial using the following dataset: Mushroom Classification. I was looking for a supervised classification problem, and I think I got it.
After running the following code...
library(caret)
dataset = read.csv("mushrooms.csv")
dim(dataset)
sapply(dataset, class)
head(dataset)
levels(dataset$class)
set.seed(100)
inTrain <- createDataPartition(y=dataset$class,p=.75,list=FALSE)
str(inTrain)
training <- dataset[inTrain,]
testing <- dataset[-inTrain,]
nrow(training)
nrow(testing)
control <- trainControl(method="cv", number=10)
metric <- "Accuracy"
train.lda <- train(class ~., data=training, method="lda", trControl=control)
... I saw the dataset had 8124 rows and 22 variables —plus the classifier—.
dim(dataset)
[1] 8124 23
However when executing train I get the following error:
Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more levels
Looking around the web, and even here in Stack Overflow, the explanation I found was that my predictor has only one factor level. Like if the class variable only took one value? Nonetheless, previously in the code I check the level of that variable, and I get its level is 2, as it takes two values.
levels(dataset$class)
[1] "e" "p"
Therefore, I do not understand why I am getting the error. What's wrong with my reasoning? What am I doing wrong?
Thank you.
Sample request:
structure(list(class = structure(c(2L, 1L, 1L, 2L, 1L, 1L, 1L,
1L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 1L,
1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 1L,
1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("e",
"p"), class = "factor"), cap.shape = structure(c(6L, 6L, 1L,
6L, 6L, 6L, 1L, 1L, 6L, 1L, 6L, 6L, 1L, 6L, 6L, 5L, 3L, 6L, 6L,
6L, 1L, 6L, 1L, 1L, 1L, 3L, 6L, 6L, 3L, 6L, 1L, 6L, 6L, 6L, 1L,
6L, 5L, 6L, 6L, 1L, 1L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 3L, 6L,
6L, 1L, 6L, 6L, 1L, 3L, 1L, 6L, 6L, 5L, 1L, 1L, 1L, 1L, 3L, 6L,
3L, 6L, 6L, 3L, 1L, 3L, 6L, 1L, 3L, 6L, 3L, 6L, 3L, 6L, 6L, 3L,
6L, 6L, 6L, 1L, 6L, 3L, 5L, 6L, 1L, 6L, 6L, 6L, 6L, 3L, 6L, 1L,
6L), .Label = c("b", "c", "f", "k", "s", "x"), class = "factor"),
cap.surface = structure(c(3L, 3L, 3L, 4L, 3L, 4L, 3L, 4L,
4L, 3L, 4L, 4L, 3L, 4L, 1L, 1L, 1L, 3L, 4L, 3L, 3L, 4L, 4L,
4L, 3L, 3L, 4L, 4L, 1L, 3L, 3L, 4L, 4L, 4L, 4L, 1L, 1L, 4L,
1L, 3L, 4L, 4L, 1L, 4L, 3L, 4L, 4L, 3L, 4L, 4L, 4L, 3L, 3L,
4L, 3L, 4L, 1L, 3L, 3L, 4L, 1L, 4L, 3L, 4L, 4L, 3L, 3L, 4L,
4L, 1L, 1L, 4L, 1L, 4L, 3L, 3L, 3L, 4L, 4L, 4L, 3L, 4L, 1L,
1L, 4L, 3L, 3L, 3L, 4L, 1L, 1L, 3L, 4L, 4L, 3L, 3L, 4L, 3L,
3L, 4L), .Label = c("f", "g", "s", "y"), class = "factor"),
cap.color = structure(c(5L, 10L, 9L, 9L, 4L, 10L, 9L, 9L,
9L, 10L, 10L, 10L, 10L, 9L, 5L, 4L, 9L, 5L, 9L, 5L, 10L,
5L, 10L, 9L, 9L, 9L, 10L, 9L, 5L, 10L, 10L, 9L, 10L, 5L,
10L, 10L, 4L, 5L, 10L, 10L, 10L, 10L, 5L, 9L, 10L, 9L, 10L,
9L, 10L, 10L, 5L, 9L, 9L, 5L, 9L, 10L, 4L, 9L, 10L, 5L, 4L,
10L, 10L, 10L, 9L, 5L, 9L, 10L, 10L, 4L, 10L, 9L, 10L, 5L,
10L, 10L, 9L, 5L, 5L, 5L, 5L, 9L, 4L, 4L, 10L, 5L, 9L, 9L,
5L, 5L, 5L, 9L, 10L, 10L, 5L, 9L, 5L, 10L, 9L, 9L), .Label = c("b",
"c", "e", "g", "n", "p", "r", "u", "w", "y"), class = "factor"),
bruises = structure(c(2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L,
2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L,
1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 1L, 1L,
2L, 1L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L,
2L), .Label = c("f", "t"), class = "factor"), odor = structure(c(7L,
1L, 4L, 7L, 6L, 1L, 1L, 4L, 7L, 1L, 4L, 1L, 1L, 7L, 6L, 6L,
6L, 7L, 7L, 7L, 1L, 7L, 4L, 1L, 4L, 7L, 1L, 4L, 6L, 1L, 4L,
7L, 4L, 4L, 4L, 4L, 6L, 7L, 1L, 4L, 1L, 4L, 6L, 7L, 1L, 1L,
4L, 4L, 4L, 4L, 1L, 4L, 4L, 7L, 7L, 1L, 6L, 1L, 4L, 1L, 6L,
1L, 4L, 4L, 4L, 6L, 4L, 1L, 1L, 6L, 4L, 4L, 4L, 1L, 1L, 4L,
4L, 4L, 7L, 1L, 6L, 7L, 6L, 6L, 4L, 6L, 1L, 4L, 4L, 6L, 6L,
4L, 1L, 4L, 6L, 1L, 4L, 1L, 1L, 1L), .Label = c("a", "c",
"f", "l", "m", "n", "p", "s", "y"), class = "factor"), gill.attachment = structure(c(2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("a", "f"), class = "factor"),
gill.spacing = structure(c(1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L,
2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L,
1L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 1L, 1L,
2L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L,
1L, 1L), .Label = c("c", "w"), class = "factor"), gill.size = structure(c(2L,
1L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 2L,
1L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 2L, 1L,
2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 2L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 2L,
2L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("b", "n"), class = "factor"),
gill.color = structure(c(5L, 5L, 6L, 6L, 5L, 6L, 3L, 6L,
8L, 3L, 3L, 6L, 11L, 5L, 6L, 5L, 5L, 6L, 6L, 5L, 5L, 6L,
5L, 11L, 3L, 6L, 6L, 11L, 5L, 6L, 3L, 5L, 6L, 8L, 6L, 11L,
5L, 11L, 8L, 5L, 6L, 6L, 3L, 8L, 11L, 6L, 5L, 11L, 6L, 11L,
11L, 5L, 5L, 5L, 5L, 11L, 6L, 11L, 5L, 8L, 5L, 5L, 3L, 3L,
6L, 5L, 6L, 11L, 11L, 8L, 8L, 3L, 11L, 8L, 5L, 8L, 6L, 8L,
11L, 6L, 5L, 11L, 6L, 6L, 11L, 5L, 11L, 6L, 11L, 6L, 6L,
5L, 3L, 3L, 6L, 3L, 8L, 6L, 3L, 3L), .Label = c("b", "e",
"g", "h", "k", "n", "o", "p", "r", "u", "w", "y"), class = "factor"),
stalk.shape = structure(c(1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L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3L,
3L, 3L, 3L, 3L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("f", "k",
"s", "y"), class = "factor"), stalk.surface.below.ring = structure(c(3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 3L, 3L, 3L, 3L,
3L, 3L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 4L, 3L, 3L, 3L, 3L, 3L, 4L, 3L, 3L,
3L, 4L, 3L, 4L, 3L, 3L, 3L, 3L, 4L, 3L, 3L, 3L, 4L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 4L, 3L, 3L, 3L), .Label = c("f", "k",
"s", "y"), class = "factor"), stalk.color.above.ring = structure(c(8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L), .Label = c("b", "c",
"e", "g", "n", "o", "p", "w", "y"), class = "factor"), stalk.color.below.ring = structure(c(8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L), .Label = c("b", "c",
"e", "g", "n", "o", "p", "w", "y"), class = "factor"), veil.type = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "p", class = "factor"),
veil.color = structure(c(3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,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L, 5L, 5L,
5L, 5L, 5L, 5L, 1L, 5L, 5L, 1L, 5L, 1L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 1L, 5L, 5L, 5L, 5L, 5L), .Label = c("e", "f",
"l", "n", "p"), class = "factor"), spore.print.color = structure(c(3L,
4L, 4L, 3L, 4L, 3L, 3L, 4L, 3L, 3L, 4L, 3L, 4L, 4L, 3L, 4L,
4L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 4L, 4L, 4L, 3L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 3L, 4L, 4L, 3L, 4L, 3L, 3L, 4L, 3L, 4L,
3L, 4L, 4L, 3L, 3L, 3L, 4L, 4L, 3L, 3L, 4L, 4L, 3L, 3L, 4L,
4L, 4L, 4L, 4L, 3L, 3L, 4L, 3L, 4L, 4L, 4L, 4L, 3L, 3L, 4L,
7L, 4L, 4L, 4L, 4L, 3L, 4L, 4L, 3L, 3L, 3L, 4L, 3L, 4L, 4L,
3L, 3L, 3L, 4L, 4L, 4L, 3L, 4L, 3L), .Label = c("b", "h",
"k", "n", "o", "r", "u", "w", "y"), class = "factor"), population = structure(c(4L,
3L, 3L, 4L, 1L, 3L, 3L, 4L, 5L, 4L, 3L, 4L, 4L, 5L, 1L, 6L,
1L, 4L, 4L, 4L, 4L, 5L, 4L, 3L, 4L, 5L, 3L, 3L, 6L, 5L, 3L,
4L, 3L, 6L, 4L, 5L, 5L, 4L, 5L, 4L, 4L, 6L, 6L, 5L, 3L, 3L,
4L, 3L, 4L, 4L, 4L, 4L, 3L, 5L, 5L, 4L, 1L, 3L, 3L, 6L, 5L,
4L, 4L, 3L, 4L, 1L, 4L, 4L, 3L, 5L, 5L, 4L, 5L, 4L, 4L, 5L,
5L, 6L, 5L, 6L, 4L, 4L, 6L, 4L, 4L, 4L, 4L, 4L, 6L, 5L, 6L,
4L, 4L, 3L, 1L, 4L, 4L, 3L, 4L, 4L), .Label = c("a", "c",
"n", "s", "v", "y"), class = "factor"), habitat = structure(c(6L,
2L, 4L, 6L, 2L, 2L, 4L, 4L, 2L, 4L, 2L, 4L, 2L, 6L, 2L, 6L,
2L, 2L, 6L, 6L, 4L, 2L, 4L, 4L, 4L, 2L, 4L, 4L, 6L, 1L, 4L,
6L, 4L, 5L, 4L, 1L, 6L, 6L, 1L, 4L, 2L, 5L, 6L, 2L, 4L, 2L,
4L, 4L, 5L, 5L, 2L, 2L, 4L, 6L, 6L, 4L, 2L, 2L, 2L, 5L, 6L,
4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 6L, 1L, 4L, 1L, 5L, 2L, 1L,
1L, 5L, 6L, 2L, 2L, 2L, 6L, 2L, 2L, 2L, 2L, 2L, 2L, 6L, 6L,
2L, 2L, 4L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("d", "g",
"l", "m", "p", "u", "w"), class = "factor")), .Names = c("class",
"cap.shape", "cap.surface", "cap.color", "bruises", "odor", "gill.attachment",
"gill.spacing", "gill.size", "gill.color", "stalk.shape", "stalk.root",
"stalk.surface.above.ring", "stalk.surface.below.ring", "stalk.color.above.ring",
"stalk.color.below.ring", "veil.type", "veil.color", "ring.number",
"ring.type", "spore.print.color", "population", "habitat"), row.names = c(NA,
100L), class = "data.frame")
First five rows of data of the .csv file plus the headers
class,cap-shape,cap-surface,cap-color,bruises,odor,gill-attachment,gill-spacing,gill-size,gill-color,stalk-shape,stalk-root,stalk-surface-above-ring,stalk-surface-below-ring,stalk-color-above-ring,stalk-color-below-ring,veil-type,veil-color,ring-number,ring-type,spore-print-color,population,habitat
p,x,s,n,t,p,f,c,n,k,e,e,s,s,w,w,p,w,o,p,k,s,u
e,x,s,y,t,a,f,c,b,k,e,c,s,s,w,w,p,w,o,p,n,n,g
e,b,s,w,t,l,f,c,b,n,e,c,s,s,w,w,p,w,o,p,n,n,m
p,x,y,w,t,p,f,c,n,n,e,e,s,s,w,w,p,w,o,p,k,s,u
e,x,s,g,f,n,f,w,b,k,t,e,s,s,w,w,p,w,o,e,n,a,g

It is possible that your data set is not randomized and that what I am about to say is only true of your samples, not the full data set BUT many of your variables have only one value that is used. Type summary(dataset) and you will quickly see some examples. For example, part of the display is:
stalk.color.below.ring veil.type veil.color ring.number
w :100 p:100 n: 0 n: 0
b : 0 o: 0 o:100
c : 0 w:100 t: 0
e : 0 y: 0
g : 0
n : 0
(Other): 0
Notice that for veil.type, there is only one possible value.
levels(dataset$veil.type)
[1] "p"
I expect that is the source of your error message.
Factors = which(sapply(dataset, class) == "factor")
sapply(dataset[,Factors], function(x) { length(levels(x)) })
Shows that veil.type is the only attribute with only one possible level.

Related

Calculating kappa statistics using irr R library

This was the question where it was shown how to use the concept.
I have naive question about this function which was give here which is this where it assigns predicted levels the cluster.
pred2labels = function(pred,actual){
pred = as.character(pred)
actual = as.character(actual)
tab = as.matrix(table(pred,actual))
assignment = colnames(tab)[max.col(tab)]
names(assignment) = rownames(tab)
assignment[pred]
}
I tried to do the same my question is do i need to generate a predicted labels for my data of clusters?
here is my data frame
dput(bb)
structure(list(FAB = structure(c(4L, 2L, 5L, 3L, 4L, 5L, 4L,
4L, 5L, 3L, 4L, 2L, 4L, 3L, 2L, 3L, 5L, 5L, 4L, 3L, 2L, 5L, 3L,
5L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 1L, 2L, 3L, 5L, 3L, 5L, 3L,
2L, 1L, 6L, 6L, 5L, 5L, 5L, 6L, 6L, 3L, 7L, 3L, 5L, 6L, 2L, 5L,
2L, 3L, 3L, 2L, 6L, 2L, 2L, 2L, 2L, 1L, 6L, 2L, 5L, 2L, 2L, 9L,
5L, 1L, 5L, 2L, 5L, 5L, 6L, 2L, 3L, 6L, 5L, 2L, 1L, 8L, 3L, 5L,
3L, 6L, 1L, 2L, 2L, 5L, 3L, 5L, 6L, 5L, 5L, 3L, 5L, 3L, 2L, 3L,
3L, 2L, 6L, 1L, 2L, 3L, 6L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 2L,
2L, 5L, 2L, 3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, 1L, 4L, 1L, 2L, 4L, 1L, 4L,
1L, 4L, 1L, 4L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 3L, 4L, 5L,
3L, 2L, 2L, 4L, 3L, 6L, 2L, 2L, 6L, 2L, 2L, 2L, 3L, 6L, 5L, 2L,
2L, 3L, 6L, 2L, 4L, 5L, 6L, 2L, 3L, 3L, 4L, 5L, 3L, 5L, 4L, 2L,
4L, 3L, 4L, 2L, 3L, 4L, 4L, 5L, 2L, 2L, 5L, 5L, 2L, 4L, 4L, 6L,
6L, 4L, 2L, 3L, 5L, 3L, 2L, 3L, 2L, 3L, 2L, 2L, 4L, 2L, 3L, 2L,
4L, 3L, 5L, 4L, 6L, 2L, 5L, 4L, 3L, 4L, 5L, 4L, 2L, 4L, 6L, 4L,
1L, 4L, 5L, 6L, 1L, 4L, 4L, 5L, 4L, 2L, 3L, 5L, 3L, 5L, 2L, 2L,
4L, 2L, 1L, 4L, 3L, 5L, 5L, 6L, 2L, 2L, 3L, 6L, 1L, 5L, 5L, 5L,
5L, 3L, 3L, 6L, 5L, 4L, 6L, 3L, 5L, 5L, 5L, 5L, 5L, 2L, 1L, 5L,
6L, 5L, 5L, 6L, 2L, 2L)), row.names = c(NA, -170L), class = "data.frame")
My steps were this
library(irr)
clus_arrange = bb %>% dplyr::select(Class,FAB)
names(clus_arrange)[1] = "clus"
clus_arrange$predicted_label = pred2labels(clus_arrange$clus,clus_arrange$FAB)
kappam.light(cluster_r)
My output is this
Light's Kappa for m Raters
Subjects = 170
Raters = 2
Kappa = 0.266
z = 6.62
p-value = 3.58e-11
My question is the approach right way of doing it what i had followed from that answer?
UPDATED ANSWER BASED ON THIS TUTORIAL
table <- table(clus_arrange$FAB, clus_arrange$clus)
table
kappam.fleiss(table, detail=TRUE)
My question is which one is methodically and logically correct

How to reshape conjoint data from wide to long?

users,
I have received a data from a conjoint survey experiment. What I want to do is to reshape from wide to long format. However, this seems to be slightly complicated. I am pretty sure it is possible to do with cj_tidy (package cregg) but can't solve it myself.
In the survey, the respondents were asked to compare two organizations that vary across 7 profiles (Efficiency Opennes Inclusion Leader Gain & System). In total, respondents were presented with four comparisons. So 2 organizations and 4 comparisons (4x2). They had to choose one of the presented organization and rate them separately after choosing one.
At the moment, the profile variables are structured in this way: org1_Efficiency_conj_1, org1_Opennes_conj1 ..etc. The first part "org" indicates whether it is the first or second organization. The last part "conj", indicated the order of the conjoint/comparison, where the "conj4" is the last comparison. The CHOICE variables also follow the order of conjoint – for example,"CHOICE_conj1", "CHOICE_conj2", where =1 means the respondent chose "org1". If =2, then org2 was chosen. The RATING> variable indicates a value from 0 to 10 for each organization: RATING_conj1_org1; RATING_conj1_org2 etc..
The current wide format of the data is not suitable for conjoint analysis - what I need is to create 8 observations for each respondent (4x2=8) where the variable CHOICE would indicate which of the organizations were chosen (where =1 if yes; and =0 if no). In a similar way, the variable RATING should indicate the rating given by respondents for both of the organizations (0 to 10).
This is how I would like the data to look like:
Note please that there are also covariates such as Q1 and Q2 in the picture, they are not a part of the experiment and should remain constant for each individual observation.
Below I share 50 observations from my real data.
> dput(cjdata_wide) structure(list(ID = 1:50, org1_Effeciency_conj_1 =
> c(3L, 2L, 1L, 3L, 3L, 2L, 3L, 3L, 3L, 3L, 2L, 1L, 1L, 1L, 1L, 1L, 3L,
> 2L, 3L, 3L, 3L, 2L, 3L, 1L, 2L, 1L, 3L, 3L, 1L, 1L, 3L, 1L, 1L, 3L,
> 3L, 2L, 3L, 2L, 3L, 2L, 1L, 1L, 3L, 2L, 1L, 1L, 1L, 2L, 2L, 1L ),
> org1_Oppenes_conj_1 = c(3L, 3L, 1L, 3L, 1L, 3L, 2L, 3L, 2L, 3L, 1L,
> 1L, 1L, 2L, 3L, 2L, 2L, 1L, 3L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 1L, 3L,
> 1L, 2L, 2L, 3L, 2L, 2L, 1L, 3L, 1L, 3L, 2L, 2L, 1L, 2L, 3L, 3L, 3L,
> 3L, 3L, 2L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 1L ), educ = c(6L, 5L, 2L, 5L, 6L, 6L, 4L, 6L,
> 3L, 5L, 4L, 5L, 6L, 4L, 4L, 6L, 6L, 6L, 3L, 6L, 5L, 6L, 5L, 5L, 3L,
> 4L, 6L, 6L, 5L, 3L, 3L, 4L, 3L, 6L, 3L, 5L, 5L, 6L, 3L, 5L, 3L, 3L,
> 3L, 3L, 4L, 5L, 5L, 4L, 2L, 3L)), class = "data.frame", row.names =
> c(NA,
> -50L))
What I have done so far is this:
library(cregg)
str(long <- cj_tidy(cjdata_wide,
profile_variables = c("All the profile variables"),
task_variables = c("CHOICE AND RATING VARIABLES HERE"),
id = ~ id))
stopifnot(nrow(long) == nrow(data)*4*2
But I'm keep getting errors. I have tried to follow the example given by the cregg package - but with no success. Any help is much appreciated! I am open to all possible ways, be it so through cregg package or tidyr for instance.
Your data not being in a standard form mades this a difficult problem. Here is a solution using the tidyr package.
The solutions involves 3 parts, dealing with the profiles, the rating and finally the rating choice.
The key to the profiles part was to pivot long and breaking up the profile names into component parts and then pivot wider for the column headings.
The rating and binary choice involved pivoting longer and then aligning the rows.
library(tidyr)
library(dplyr)
#Get the categories part correct
answer <-cjdata_wide %>% pivot_longer(cols=starts_with("org"), names_to=c("org", "Cat", "conj", "order"), values_to= "values", names_sep="_") %>% select(-c("conj"))
answer <-answer %>% select(!starts_with("RATING") & !starts_with("CHOICE"))
answer <-pivot_wider(answer, names_from = "Cat", values_from = "values")
#get the ratings column corretn
rating <-cjdata_wide %>% select(starts_with("RATING") )
rating <- rating%>% pivot_longer(cols=everything(), names_to=c("Rating", "conj", "order"), values_to= "Choice_Rating", names_sep="_") %>% select(-c("conj"))
answer$Choice_Rating <- rating$Choice_Rating
#Get the choice correct
choice <-cjdata_wide %>% select(starts_with("CHOICE") )
choiceRate <- choice%>% pivot_longer(cols=everything(), names_to=c("Choice", "conj"), values_to= "Choice_Rating", names_sep="_") %>% select(-c("conj"))
answer$Choice_binary <-ifelse(substr(answer$org, 4,4) == rep(choiceRate$Choice_Rating,each=2), 1, 0)
answer
It may be possible to simplify the above. Good luck.
Update per Comment
The final data frame has pairs of rows which corresponds to org 1 or 2. I duplicated the choice so that Choice_Rating column is the same length as the Organization ("org" column). I then compared Choice_Rating & Organization and setting the final value to either 0 or 1 depending on the match.
For question in the comment, A simple way is to convert the factor column to integers with as.integer() function, then the first factor becomes 1 and the second becomes 2 etc. (may need to relevel in order to get the proper order).
Another option is to create a new "org" column with your factor names properly listed.
Hopefully this provides enough guidance.

How to add color in emmeans graph?

I would like to have one color for each level in x axis. I have tried different ways to enter the colour via col argument, but it doesn't seem to work. So far:
library(emmeans)
library(ggplot2)
df <- structure(list(Scanner = structure(c(4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L), .Label = c("a", "b", "c", "d", "e",
"f"), class = "factor"), Reta = structure(c(1L, 2L, 3L, 4L, 5L,
6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L,
4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L,
2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L,
6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L,
4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L,
2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L,
6L, 1L, 2L, 3L, 4L, 5L, 6L), .Label = c("A", "B", "C", "D", "E",
"F"), class = "factor"), erro = c(0.0120000000000005, 0.0289999999999999,
0.088000000000001, 0.00600000000000023, -0.0289999999999964,
0.106999999999999, 0.0850000000000009, 0.172999999999998, 0.183999999999997,
0.208000000000006, 0.192, 0.0869999999999997, -0.0140000000000029,
-0.0420000000000016, -0.0350000000000037, 0.00600000000000023,
0, -0.0100000000000016, 0.167000000000002, 0.276, 0.262, 0.0790000000000006,
0.426000000000002, 0.202999999999999, -0.181000000000004, 0.0560000000000009,
-0.0219999999999985, -0.264999999999993, 0.106000000000002, 0.154999999999998,
-0.0420000000000016, 0.0670000000000002, 0.176000000000002, -0.18,
0.215000000000003, 0.189, -0.036999999999999, 0.169, 0.103000000000002,
-0.622999999999998, 0.268999999999998, 0.106999999999999, -0.0140000000000029,
0.169999999999998, 0.115000000000002, -0.622, 0.276000000000003,
0.0969999999999978, -0.0320000000000036, 0.155999999999999, 0.116,
-0.290999999999997, 0.283000000000001, 0.0439999999999969, 0.0940000000000012,
-0.117000000000001, 0.0249999999999986, 0.00900000000000034,
0.0760000000000005, 0.109999999999999, 0.0549999999999997, 0.0470000000000006,
-0.027000000000001, 0.0130000000000052, 0.036999999999999, 0.0139999999999993,
0.0420000000000016, 0.0459999999999994, -0.109999999999999, 0.007000000000005,
0.0339999999999989, 0.104999999999997, -0.240000000000002, 0.0940000000000012,
-0.0570000000000022, -0.352999999999994, 0.0129999999999981,
0.113, -0.251000000000005, 0.0760000000000005, -0.00200000000000244,
NA, 0.112000000000002, 0.0839999999999996, -0.242000000000004,
0.0530000000000008, -0.134999999999998, -0.446999999999996, 0.118000000000002,
0.075999999999997, -0.0769999999999982, -0.0590000000000011,
-0.0870000000000033, -0.445999999999998, 0.158999999999999, 0.0829999999999984,
-0.270000000000003, -0.0210000000000008, -0.0840000000000032,
-0.189999999999998, 0.116999999999997, 0.0519999999999996, -0.0960000000000036,
-0.0859999999999985, -0.177, -0.271999999999998, 0.0679999999999978,
0.0439999999999969)), row.names = c(NA, -108L), class = c("tbl_df",
"tbl", "data.frame"))
m1 <- lm(erro ~ Scanner*Reta, data = df)
l1 <- emmeans(m1, "Scanner", "Reta")
emmip(l1, ~ Reta |Scanner,
col = rep(cols, each = 108/6),
CIs = TRUE) +
geom_hline(yintercept = 0, linetype = 2) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(y = "Erro absoluto (mm)")
Right now, I think one of solution like this:
cols = RColorBrewer::brewer.pal(6,"Paired")
emmip(m1 ,Scanner~Reta,CIs =TRUE) + facet_wrap(~Scanner) +
geom_hline(yintercept = 0, linetype = 2) +
theme_bw()+
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(y = "Erro absoluto (mm)")+
scale_color_manual(values=cols)

Negative Binomial in R: glm.nb: In sqrt(1/i) : NaNs produced, and other problems

I am running a negative binomial regression.
I would like to know why I have the following errors:
In sqrt(1/i) : NaNs produced
It appears that there are some negative values in "i", but how do I avoid that?
Another one is:
In loglik(n, th, mu, Y, w) : value out of range in 'lgamma'
It is probably a consequences of the first error, so if I fix the first one, the second might be gone. Or maybe not.
In some other cases I am able to calculate the regression but the following output seems strange for me:
(Dispersion parameter for Negative Binomial(10684331573) family taken
to be 1)
Null deviance: 8779.49 on 359 degrees of freedom
Residual deviance: 270.32 on 200 degrees of freedom
AIC: 2074.7
Number of Fisher Scoring iterations: 1
Theta: 10684331573
Std. Err.: 615849693813
2 x log-likelihood: -1752.749
Do these numbers seem okay? I mean the dispersion parameter, theta and standard error. They look enormously big to me and therefore I am not sure if the results are okay.
I never had any problems like that using poisson regression, but then I realized that I have an overdispersed data and that is why I am using negative binomial. However, I am having a lot of troubles with this one.
Here is the code:
negbin <- glm.nb(Freq ~ cluster*gender*agecombined*educ, maxit=100)
mod.good <- step(negbin, direction='both', maxit=100)
And here is the dput of the whole dataset:
structure(list(gender = structure(c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 2L,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69L, 54L, 33L, 15L, 12L,
4L, 5L, 1L, 0L, 0L, 2L, 4L, 12L, 14L, 17L, 17L, 23L, 32L,
16L, 17L, 18L, 6L, 4L, 2L, 17L, 7L, 8L, 4L, 5L, 0L, 1L, 0L,
0L, 0L, 53L, 42L, 82L, 58L, 81L, 60L, 42L, 35L, 16L, 14L,
22L, 6L, 83L, 40L, 62L, 54L, 43L, 46L, 26L, 12L, 15L, 3L,
3L, 3L, 11L, 13L, 11L, 23L, 16L, 18L, 11L, 5L, 1L, 3L, 1L,
1L, 26L, 44L, 34L, 54L, 25L, 41L, 19L, 17L, 10L, 3L, 3L,
0L, 4L, 4L, 7L, 14L, 22L, 31L, 14L, 34L, 14L, 33L, 14L, 20L,
7L, 11L, 22L, 11L, 14L, 8L, 8L, 1L, 2L, 0L, 1L, 2L, 29L,
65L, 34L, 84L, 36L, 65L, 28L, 39L, 16L, 15L, 16L, 9L, 25L,
51L, 12L, 38L, 23L, 29L, 22L, 19L, 7L, 5L, 5L, 1L, 7L, 16L,
14L, 35L, 6L, 27L, 8L, 5L, 1L, 1L, 1L, 0L, 24L, 57L, 29L,
53L, 24L, 28L, 11L, 9L, 7L, 2L, 0L, 0L, 3L, 7L, 1L, 8L, 2L,
18L, 5L, 13L, 10L, 11L, 5L, 10L, 3L, 1L, 5L, 13L, 4L, 2L,
2L, 1L, 1L, 0L, 0L, 0L, 14L, 51L, 21L, 77L, 23L, 50L, 25L,
31L, 17L, 16L, 13L, 13L, 19L, 52L, 24L, 59L, 18L, 44L, 9L,
20L, 6L, 3L, 7L, 2L, 14L, 28L, 34L, 47L, 29L, 47L, 15L, 13L,
9L, 3L, 2L, 0L, 46L, 75L, 124L, 81L, 67L, 45L, 33L, 15L,
9L, 4L, 5L, 3L, 0L, 10L, 6L, 19L, 12L, 28L, 22L, 37L, 31L,
41L, 26L, 31L, 7L, 6L, 21L, 13L, 6L, 7L, 8L, 2L, 2L, 1L,
0L, 0L, 67L, 89L, 116L, 159L, 99L, 102L, 64L, 80L, 42L, 25L,
25L, 8L, 108L, 123L, 60L, 97L, 68L, 66L, 44L, 35L, 12L, 5L,
9L, 2L, 7L, 3L, 53L, 15L, 33L, 3L, 8L, 3L, 4L, 0L, 0L, 0L,
48L, 19L, 76L, 40L, 55L, 11L, 16L, 1L, 4L, 1L, 2L, 0L, 6L,
7L, 21L, 22L, 18L, 23L, 32L, 37L, 40L, 13L, 23L, 10L, 4L,
2L, 19L, 2L, 8L, 3L, 6L, 0L, 1L, 0L, 1L, 0L, 68L, 37L, 90L,
42L, 76L, 38L, 47L, 16L, 29L, 5L, 18L, 2L, 82L, 32L, 62L,
27L, 44L, 22L, 20L, 8L, 8L, 2L, 1L, 0L)), .Names = c("gender", "agecombined", "educ", "cluster", "Freq"), row.names = c(NA,
-360L), class = "data.frame")

Plotting a stacked bar plot?

I have the following data:
structure(list(Time = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L), Type = c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L,
1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L,
1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L,
1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L), Value = c(848565.34,
1463110.61, 626673.64, 277708.41, 841422.11, 956238.14, 461092.16,
208703.75, 800837.48, 1356164.25, 549509.34, 300241.53, 851247.9714,
1353358.318, 598536.5948, 307485.0918, 332042.2275, 666157.8721,
194981.1566, 79344.50328, 831003.6952, 1111311.517, 521632.3074,
274384.1731, 1174671.569, 1070301.745, 454876.1589, 351973.2418,
5631710.101, 279394.6061, 119034.4969, 39693.31587, 1166869.32,
1156855.09, 369816.8152, 274092.5751, 924474.1129, 975028.0207,
449213.7419, 213855.3067, 1967188.317, 178841.604, 43692.69319,
12493.90538, 835142.6168, 876273.4462, 354154.644, 182794.3813,
1158096.251, 998647.6908, 566726.9865, 195099.4295, 1798902.332,
171519.4741, 81644.02724, 12221.41779, 1301775.314, 920464.9992,
294140.4882, 175626.9677, 2179780.499, 1838687.535, 978775.2674,
366668.3462, 5385970.324, 177527.1577, 65310.32674, 5986.871716,
2250834.171, 1547858.632, 666444.2992, 251767.3006, 1786086.335,
1597055.451, 563976.9719, 309186.1626, 487105.824, 279712.1658,
86471.46603, 24434.05486, 1563940.414, 1409428.038, 531425.682,
257056.5524, 1685501.271, 1371943.438, 881348.5022, 313355.8284,
170771.9118, 155596.7479, 59881.60825, 12090.57989, 1668571.543,
1150257.058, 563054.758, 306767.0344, 2214849.859, 1724719.891,
822092.2031, 443194.4609, 8897796.235, 87491.42925, 10699.30103,
18131.89738, 2137240.993, 1476873.778, 741685.9913, 549539.9735,
1362085.657, 1266106.09, 448653.8889, 278236.8416, 1671665.39,
95239.07396, 54173.57043, 10125.82011, 1335200.152, 1167824.903,
426738.1845, 261255.2092)), .Names = c("Time", "Type", "Value"
), row.names = c(NA, -120L), class = "data.frame")
I am trying to plot a stacked bar graph that looks like this:
I know that adding position="identity" or position="dodge" produces different types of bar plots but am not sure how to produce the above chart with both types. Any suggestions?
ggplot(df, aes(x = factor(Time), y = Value, fill = factor(Type))) +
geom_bar(stat="identity", position = "stack")
ggplot(df, aes(x = factor(Time), y = Value, fill = factor(Type))) +
geom_bar(stat="identity", position = "dodge")
You can do one or the other but not both. When they are dodged, the different values of type are being used. By adding a color outline, you can see that.
ggplot(df, aes(x = factor(Time), y = Value, fill = factor(Type))) +
geom_bar(stat="identity", position = c("dodge"), colour = 'black')

Resources