R) Create double-labeled MDS plot

后端 未结 2 1788
轮回少年
轮回少年 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

    0 讨论(0)
  • 2021-01-07 16:08

    Actually, you can do this directly in default plot command which can take pch and col arguments as vectors. Use:

    with(data, plot(mds, col = as.numeric(Study), pch = as.numeric(Disease), asp = 1)
    

    You must use asp = 1 when you plot cmdscale results: both axes must be scaled similarly. You can also add xlab and ylab arguments for nicer axis labels. For adding legend and selecting plotting characters and colours, see other responses.

    0 讨论(0)
提交回复
热议问题