Skip to Content
R 錦囊妙計
book

R 錦囊妙計

by Paul Teetor
January 2014
Beginner to intermediate
488 pages
8h 1m
Chinese
GoTop Information, Inc.
Content preview from R 錦囊妙計
276
|
第十章
在於,使用
plot
函數繪製第一條線之後,接著使用
lines
函數,繪製後續的其他直線。
如下所示,使用
lines
函數可添加直線至既有圖形上,而且允許設定不同的樣式、寬
度,和顏色:
> plot(x, y.democr, type="l", col="blue")
> lines(x, y.republ, col="red")
> lines(x, y.indeps, col="yellow")
其中,首先使用
plot
函數初始化圖形視窗,並將第一條線設為藍色。接著使用
lines
數繪製另外兩條直線,分別設定為紅色與黃色。
延伸資訊
錦囊 10.12 關於繪製基本直線圖。
10.14 繪製多個資料集
問題點
您想將多個資料集的繪圖結果呈現於一張圖上。
解決方案
使用高階圖形函數(如:
plot
curve
)初始化圖形,然後使用低階圖形函數(如:
lines
points
)來添加額外的資料集。
當初始化圖形時,需注意畫布(canvas)的正確尺寸。使用
xlim
ylim
兩個參數,設
定足夠的畫布空間來容納所有資料集,而不只是第一個資料集。以下程式碼片段顯示如
何使用
range
函數計算範圍,並設定
xlim
ylim
參數。它假設您有兩個資料集,一個
x1
y1
代表;另一個則由
x2
y2
代表:
> xlim <- range(c(x1,x2))
> ylim <- range(c(y1,y2))
> plot(x1, y1, type="l", xlim=xlim, ylim=ylim)
> lines(x2, y2, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

R 语言经典实例(原书第 2 版)

R 语言经典实例(原书第 2 版)

J.D. Long, Paul Teetor
優雅的SciPy|Python科學研究的美學

優雅的SciPy|Python科學研究的美學

Juan Nunez-Iglesias, Stéfan van der Walt, Harriet Dashnow
C++语言导学(原书第2版)

C++语言导学(原书第2版)

本贾尼 斯特劳斯特鲁普

Publisher Resources

ISBN: 9789862769829