When I run the code below in the R console, I get the following error in line 10:
"Error in lda.default(x, grouping, ...) : variables 5 6 appear to be constant within groups"
However the rest of the code is still processed and the data is plotted. But when I integrate this code into my shiny app, the plot panel shows the error message and nothing else.
Is there a way to get around this?
Input:
require(MASS)
require(ggplot2)
require(scales)
require(gridExtra)
x = 'Species'
ex = iris[, x]
lda <- lda(ex ~ ., iris)
prop.lda = lda$svd^2/sum(lda$svd^2)
plda <- predict(object = lda, newdata = iris)
dataset = data.frame(colAndShape = iris[,"Species"], lda = plda$x)
p1 <- ggplot(dataset) + geom_point(aes(lda.LD1, lda.LD2, colour = colAndShape, shape = colAndShape), size = 2.5) +
labs(x = paste("LD1 (", percent(prop.lda[1]), ")", sep=""),
y = paste("LD2 (", percent(prop.lda[2]), ")", sep=""))
grid.arrange(p1)
Console output:
> require(MASS)
> require(ggplot2)
> require(scales)
> require(gridExtra)
>
> x = 'Species'
>
> ex = iris[, x]
>
> lda <- lda(ex ~ ., iris)
Error in lda.default(x, grouping, ...) :
variables 5 6 appear to be constant within groups
>
> prop.lda = lda$svd^2/sum(lda$svd^2)
>
> plda <- predict(object = lda,
+ newdata = iris)
>
> dataset = data.frame(colAndShape = iris[,"Species"], lda = plda$x)
>
> p1 <- ggplot(dataset) + geom_point(aes(lda.LD1, lda.LD2, colour = colAndShape, shape = colAndShape), size = 2.5) +
+ labs(x = paste("LD1 (", percent(prop.lda[1]), ")", sep=""),
+ y = paste("LD2 (", percent(prop.lda[2]), ")", sep=""))
>
> grid.arrange(p1)