I intend to create a boxplot and highlight the significance level of pairwise comparisons. This has been dealt in a previous post.
When I do the same for my data-set, I get the following error:
"Incompatible lengths for set aesthetics: x, y"
Here's an example data-set to illustrate the problem -
data1<-data.frame(island = c("A", "B", "B", "A", "A"), count = c(2, 5, 12, 2, 3))
g1<-ggplot(data1) + geom_boxplot(aes(x = factor(island), y = count))
g1 + geom_path(x = c(1, 1, 2, 2), y = c(25, 26, 26, 25))
I get the error while running the third line of the code, while the boxplot turns out alright. I suspect I'm missing out on something very trivial, but I'm unable to catch it. I'd greatly appreciate any help.
I'm adding this as an answer, because it is too long to be a comment, but it is meant as a supplement to the already accepted answer.
In a similar situation I tried employing
geom_path
to a colored barplot, but got this error:Then it turns out that the
fill
option should be turned "off", otherwise it follows the one in the precedingggplot
call, which asks for theSpecies
column and leads such error.Because you don't have an explicit
data
argument ingeom_path
, data from thedata
argument inggplot
is 'inherited' togeom_path
. The machinery then chokes when it finds out that the length of the x and y variables in 'data1' differs from the length of the x and y vectors in thegeom_path
call. Try to create a separate data frame forgeom_path
and use thedata
argument: