Home>

Perhaps if you search well, you may find a solution, but
I could not go to me.
Thank you for your professor.

R is trying to make a drawing using TidyVerse and QIIME2R.

Metadata <
-READ_Q2METADATA ("Metadata.tsv")
PCo <
-READ_QZA ("UNWEIGHTED_UNIFRAC_PCOA_RESULTS.QZA")
Colpal <
-c ("red", "blue", "magenta", "Deepskyblue", "maroon4", "darkgreen", "Orange", "blueviolet", "Honeydew 4", "black", "salmon4")
PCOU $ DATA $ Vectors% >
%
  SELECT (SampleID, PC1, PC2)% >
%
  Left_Join (Metadata)% >
%
  GGPLOT (AES (X= PC1, Y= PC2, COLOR= `WKS`, Shape=` Experiment-Sex`) +
  GEOM_POINT (Alpha= 0.7, SIZE= 3) +
  theme_bw () +
  Scale_Shape_Manual (Values ​​= C (16, 17, 15, 18, 18), name= "Experimental PRIOD-SEX") +
  scale_color_manual (Values ​​= colpal, name= "Post inoculum day") +
  GUIDES (Shape= Guide_Legend (ORDER= 1), COLOR= GUIDE_LEGEND (ORDER= 2) +
  GGTITLE ("UNWEIGHTED UNIFRAC") +
  Theme (ASPECT.RATIO= 1, PLOT.TITLE= ELEMENT_TEXT (SIZE= 20, FACE= "BOLD"))

Reference: Plotting PCoA

To set this, color legend in order,

scale_color_manual (Values ​​= colpal, name= "Post inoculum day", labels= c ("1d", "2d", ..., "Origin_inoculum") +
When "Labels" is added to the part of

and "SCALE_COLOR_MANUAL",
The number of days of the legend is the order as desired, but it will not match the drawing plot color.
(1D is red, 2D will be blue ...

If you modify it, will the drawing plot and legends will match?

By the way, "Experimental PRIOD-SEX" is consistent with three-dimensional depiction.

If you are not enough supplementary information, please specify in your comment.
Thank you very much.

  • Answer # 1

    helpVALUESFor explanation of arguments

    The Values ​​Will Be Matched in Order (USUALLY ALPHABETICAL) with the limits of the scale, or with breaks if Provided.

    is.

    Specify a colorVALUESIf you set,wksWhat is the value of the column?breaksYou need to specify. If not set, the correspondence may be confusing because the order of sorting is performed. AndlabelsIs not to overwrite the label of the legend and not specifies the correspondence.

    Therefore,breaksAlsolabelsSpecify the same thing as specified in.

    SHAPEIt is said that the display of the correct display is because the order does not change.

    Example:

    G <
    -GGPLOT (IRIS, AES (X= SEPAL.LENGTH, SEPAL.WIDTH, COLOR= SPECIES)) + GEOM_POINT ()
    g
    G + Scale_Color_Manual (Values ​​= C ("Red", "Blue", "Magenta"), Labels= C ("Versicolor", "SETOSA", "Virginica"))
    G + Scale_Color_Manual (Values ​​= C ("Red", "Blue", "Magenta"), Breaks= C ("Versicolor", "Setosa", "Virginica"), Labels= C ("Versicolor", "Setosa", "VIRGINICA"))
    
    

    supplementary :breaks,VALUES,labelsIn addition to giving each,VALUESBy giving a named vectorbreaksWhenVALUESYou can specify the correspondence between the following ways.

    G + Scale_Color_Manual
      VALUES= C (Versicolor= "Red", setosa= "Blue", Virginica= "MAGENTA"),
      Labels= C ("Versicolor", "setosa", "Virginica"))
    
    

    https://ggplot2.tidyverse.org/reference/scale_manual.html

  • Answer # 2

    helpVALUESFor explanation of arguments

    The Values ​​Will Be Matched in Order (USUALLY ALPHABETICAL) with the limits of the scale, or with breaks if Provided.

    is.

    Specify a colorVALUESIf you set,wksWhat is the value of the column?breaksYou need to specify. If not set, the correspondence may be confusing because the order of sorting is performed. AndlabelsIs not to overwrite the label of the legend and not specifies the correspondence.

    Therefore,breaksAlsolabelsSpecify the same thing as specified in.

    SHAPEIt is said that the display of the correct display is because the order does not change.

    Example:

    G <
    -GGPLOT (IRIS, AES (X= SEPAL.LENGTH, SEPAL.WIDTH, COLOR= SPECIES)) + GEOM_POINT ()
    g
    G + Scale_Color_Manual (Values ​​= C ("Red", "Blue", "Magenta"), Labels= C ("Versicolor", "SETOSA", "Virginica"))
    G + Scale_Color_Manual (Values ​​= C ("Red", "Blue", "Magenta"), Breaks= C ("Versicolor", "Setosa", "Virginica"), Labels= C ("Versicolor", "Setosa", "VIRGINICA"))
    
    

    supplementary :breaks,VALUES,labelsIn addition to giving each,VALUESBy giving a named vectorbreaksWhenVALUESYou can specify the correspondence between the following ways.

    G + Scale_Color_Manual
      VALUES= C (Versicolor= "Red", setosa= "Blue", Virginica= "MAGENTA"),
      Labels= C ("Versicolor", "setosa", "Virginica"))
    
    

    https://ggplot2.tidyverse.org/reference/scale_manual.html