Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About the custom command to modified the ggplot object #93

Closed
MarcoDiazCOL opened this issue Apr 24, 2024 · 4 comments
Closed

About the custom command to modified the ggplot object #93

MarcoDiazCOL opened this issue Apr 24, 2024 · 4 comments

Comments

@MarcoDiazCOL
Copy link

Hi. I really like your work.

Is there anyway to remove the custom annotations from the plotScores graphs? Sometimes the annotation "centered/nonscale/classical" the overlapped with the data in the plot.

Thank you

@bryanhanson
Copy link
Owner

Hey, thanks, you made my day!

I would suggest making the plot as you have been and then use p + coord_cartesian(...) and set the plot limits a little larger so that the annotation doesn't stomp on data.

Let me know if this works for you.

@bryanhanson
Copy link
Owner

Did you solve your problem?

@MarcoDiazCOL
Copy link
Author

MarcoDiazCOL commented May 1, 2024

Hi Brayan,

Apologies for not responding earlier. I ultimately decided not to use the PCA biplot. Instead, I focused on the cluster analysis and the heatmap. I'm currently analyzing the spectral reflectance in the UV range of 200 to 400 nm from six rose cultivars using ChemoSpec. This approach has been very helpful because the baseline and normalization procedures were straightforward. Additionally, the cluster analysis effectively grouped the cultivars.

I didn't use the biplot because I only have one sample for each cultivar. While the heatmap was generated, it has been challenging to interpret because not all the data is shown on the x-axis. Specifically, the graph only displays certain frequencies and not in wavelength order (presumably due to clustering).

Do you know if it's possible to display all the data from the frequency axis on the heatmap and/or to prevent the heatmap from clustering by columns but only by rows?

abaxial Dendogram

Again thanks for your work and your help.

@bryanhanson
Copy link
Owner

Good questions!

After looking around a bit, it appears one cannot cluster just the rows and leave the columns unchanged. hmapSpectra() actually doesn't do much except pass the data on to the seriation package, and there's a lot of control possible there, but not what you ask apparently. In fact, seriation also passes its processed data to heatmap() which is built into R itself. But again, I don't see anyway to not process the columns.

Even so, please re-read the help file for hmapSpectra() especially the part that talks about interpretation. It can be a little counter intuitive but very powerful. Basically one can identify which frequencies are most important in driving the clustering of the samples. But there are other ways to learn that which might be easier to appreciate, for instance sPlotSpectra(), which gives the most influential frequencies, or plotLoadings() which gives a broader view of important frequencies.

Also be guarded in your interpretation of any of this since you don't have replicates on cultivars.

On your other question about seeing all the x-axis data. It's all there, it just that the functions don't label everything because that would be impossible to read. One thing that helps sometimes is to make a large version of the plot (I can show you how if you like). Another is the object returned by the function contains the x-axis re-ordered order, and you can use that to "see" the x-axis results in a little more detail. From the example in ?hmapSpectra we can do:

 data(SrE.IR)
  # Label samples and frequencies by passing arguments to stats:heatmap
  # Also make a few other nice plot adjustments
  res <- hmapSpectra(IR,
    col = heat.colors(5),
    row_labels = IR$names, col_labels = as.character(round(IR$freq)),
    margins = c(4, 6)
    )

# Now extract the order from the res object (which is structured a bit strangely):
ord <- get_order(res$o[2])

# and use it to index the frequency:
IR$freq[ord]

# which give the full exact order along the x-axis:

 [1] 1760.777 1762.706 1764.634 1766.563 1768.491 1770.420 1772.348 1774.277 1660.492
[10] 1662.420 1664.349 1666.277 1668.206 1672.063 1670.135 1673.992 1675.920 1677.849
[19] 1679.777 1681.706 1683.635 1685.563 1687.492 1689.420 1691.349 1758.849 1756.920
[28] 1754.991 1753.063 1731.849 1729.920 1727.991 1726.063 1724.134 1722.206 1693.277
[37] 1695.206 1697.135 1699.063 1718.349 1720.277 1733.777 1751.134 1735.706 1737.634
[46] 1749.206 1747.277 1739.563 1745.349 1741.491 1743.420 1716.420 1700.992 1702.920
[55] 1714.492 1712.563 1704.849 1710.634 1706.777 1708.706

Another approach: if you use xlim in your hmapSpectra() call or use removeFreq() to limit the range of interest, you can zoom in a bit.

Finally, if you are not getting the results you want, if you have a vis reflection instrument there's anthocyanin peaks over at 550 nm or so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants