I am making a plot using ggplot2 n R 3.2.3, with a template that I've been using for long time successfully. I am now getting the same error as in here and here (replacement has %d rows, data has %d
).
The only difference from the other times I used it is that I'm making the plot using the R kernel of Jupyter Notebook.
Commenting each line at once I reduced the ones responsible for the error to these:
P1 <- ggplot(data=x, aes(x=Lf_per_tree, y=Section, fill=Section, col=Section)) +
geom_jitter() +
scale_fill_manual("", values=Colors) +
scale_color_manual("", values=Colors)
If I remove the scale_color
functions, the plot works just fine, so it must be those. Since I used them many times within my template though, I suspect that something is off between the x
declared in data=
and the Colors
declared in scale_fill/color
.
This is how head(x)
looks like:
Lf_per_tree Section
1 7 A
2 5 B
.....
This is how Colors
looks like:
$A
[1] "black"
$B
[1] "#C4B3A2"
.....
The scale_color_manual
and scale_fill_manual
functions in the plot basically take what is declared in aes()
within ggplot()
(column "Section") and convert that into a color using the list Colors
.
This has always worked until now and I have no clue why. Just by the feels of it, it seems as this issue is very close to mine but I couldn't solve it like they do there.
Anyone knows something about this?