Open Avtober opened 2 years ago
Hi @Avtober
Did you include scale_fill_brewer
in your plot to use the Set1 palette? As the error message says, you have too many genera where as the Set1 palette can only give you 9 colours.
Hi @ycl6, I don't think I did use that in my plot. I only included the code above.
Thanks Anya
Hi @Avtober
If you phyloseq object is Namdata.platy
, what if you make a plot with just plot_bar(Namdata.platy, fill = "Genus")
(i.e. without adding ggplot2 functions)?
HI @ycl6
If I try that with just loading phyloseq and not ggplot2 then I get this message:
plot_bar(Namdata.platy, fill = "Genus") Error in scale_fill_brewer(palette = palname, ...) : could not find function "scale_fill_brewer"
If I then load ggplot2 I get the same message as before:
plot_bar(Namdata.platy, fill = "Genus") Warning message: In RColorBrewer::brewer.pal(n, pal) : n too large, allowed maximum for palette Set1 is 9 Returning the palette you asked for with that many colors
Thanks, Anya
Hi @Avtober
It's possible that you are not using the phyloseq's plot_bar
function, but a function of the same name but from another package.
phyloseq's plot_bar
should not have include scale_fill_brewer
or use the brewer.pal
function.
What if you use phyloseq::plot_bar(Namdata.platy, fill = "Genus")
to make sure you are using the function from the phyloseq package.
Using your error message, I found this workflow that seems to replace ggplot's scale_colour_discrete
and scale_fill_discrete
to use Set1
palette. Maybe that's what happened.
https://github.com/mbontrager/16S_processing/blob/40cd41c6096bcb35237163158c5372d5deb65181/R/16S_analysis.R#L28-L37
Thanks @ycl6
I am still getting the same error message so maybe I should uninstall the R colour brewer or uninstall and reinstall phyloseq? Maybe one is overiding the other? I will have a look at that workflow too.
Thanks Anya
Hi @ycl6
I have just noticed that when I load the ggplot2 library : get this message:
Attaching package: ‘ggplot2’
The following object is masked by ‘.GlobalEnv’:
scale_fill_discrete
Could this be the problem?
Thanks Anya
Hi @Avtober
Yes, I think another package has the same function name scale_fill_discrete
that's overriding the ggplot2's function.
After you load your packages, run ?scale_fill_discrete
and see what is the package.
Below is the example of the manual of scale_fill_discrete
from ggplot2
scale_colour_discrete package:ggplot2 R Documentation
Discrete colour scales
Description:
The default discrete colour scale. Defaults to
‘scale_fill_hue()’/‘scale_fill_brewer()’ unless ‘type’ (which
defaults to the ‘ggplot2.discrete.fill’/‘ggplot2.discrete.colour’
options) is specified.
Usage:
scale_colour_discrete(..., type = getOption("ggplot2.discrete.colour"))
scale_fill_discrete(..., type = getOption("ggplot2.discrete.fill"))
Hi @ycl6
It was saying that it was ggplot2 but I noticed that Scale_fill_discrete was also in my global environment and had something to do with DEseq. I ended up just starting a new project with my old scripts and now it is working fine.
Thanks for your help Anya
Hi there. I initially used the following code to make a bar plot of my classifications. It initially worked fine and gave me different colours. However I recently needed to make another plot and used the same code but now it is saying that there are not enough colours. I am not sure why it was working fine but now is not. Below is the code and the two bar plots.
Nambarplot.platy <- plot_bar(Namdata.platy) Nambarplot.platy <- plot_bar(Namdata.platy, fill = "Genus") Nambarplot.platy <- Nambarplot.platy + facet_wrap(vars(genus), scales = "free_x", nrow = 1) plot(Nambarplot.platy)
Original plot:![image](https://user-images.githubusercontent.com/84408079/155293609-c7e973c4-ef8d-4307-8c16-0d5491eb2a0a.png)
but when I try to make the same plot now it says the following:
n too large, allowed maximum for palette Set1 is 9 Returning the palette you asked for with that many colors. Do you know why this is?
Thanks Anya