R) Create double-labeled MDS plot

后端 未结 2 1806
轮回少年
轮回少年 2021-01-07 15:25

I am totally new to R.
I have expression profile data which is preprocessed and combined. Looks like this (\"exp.txt\")

       STUDY_1_CANCER_1   STUDY_         


        
2条回答
  •  暖寄归人
    2021-01-07 16:08

    First create an empty plot, then add the points with specified colors/shapes.

    Here's an example:

    require(vegan)
    data(dune)
    data(dune.env)
    
    mds <- cmdscale(vegdist(dune, method='bray'))
    
    
    # set colors and shapes
    cols = c('red', 'blue', 'black', 'steelblue')
    shps = c(15, 16, 17)
    # empty plot
    plot(mds, type = 'n')
    # add points
    points(mds, col = cols[dune.env$Management], pch = shps[dune.env$Use])
    # add legend
    legend('topright', col=cols, legend=levels(dune.env$Management), pch = 16, cex = 0.7)
    legend('bottomright', legend=levels(dune.env$Use), pch = shps, cex = 0.7)
    

    Note that factors are internally coded as integers, which is helpful here.

    > levels(dune.env$Management)
    [1] "BF" "HF" "NM" "SF"
    

    so

    cols[dune.env$Management]
    

    will take the first entry of cols for the first factor levels. Similariy for the different shapes.

    Finally add the legend. Of course this plot still needs some polishing, but thats the way to go...

    BTW: Gavin Simpson has a nice blogpost about customizing ordination plots.

    enter image description here

提交回复
热议问题