R Language Drawing tips: Use two different scales in the same sheet

Source: Internet
Author: User

Writing in the process encountered this drawing problem, need to add a diversity curve in the Manhattan map, the scale difference between the two is relatively large, directly with the Lines function to add, the effect of tragedy. Force the scale gap between the two pictures in the same picture, the effect is probably the following look.

This diagram is not easy to see the difference between the data. To solve this problem, you can use the Twood.plot function in the R Plotrix package to use two different scales in the same diagram, the function is described as follows:

After using this function, draw again:

Ignoring the color collocation and aesthetic problems, at least more intuitive than the previous figure, the two kinds of information can be seen more clearly. Finally put the Code ~ ~ ~

#########################################

# # Plot with the ordinates # #

#########################################

Library (Plotrix)
Set.seed (1234)
Pvalue <-runif (100,0,0.005)
Diversity <-runif (100,0,5)

# Fig 1
x <-seq (1,100)
Pvalue <--log (pvalue)
Plot (c (0,100), C (0,12), type= ' n ', xlab= ' Position ', ylab= ' value ')
Points (pvalue,pch =, col= ' gray50 ')
Lines (x,diversity,col= ' blue ')

# Fig 2
Twoord.plot (x,pvalue,x,diversity,xlab= ' Position ', ylab= '-log pvalue ',
rylab= ' diversity ', lcol= ' gray50 ', rcol= ' Blue ', type=c (' P ', ' l '), lpch=20)

R Language Drawing tips: Use two different scales in the same sheet

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.