R中間言語図面:図ポリライン

図ポリライン
オレンジの木の年齢及び第五年輪データが含まれ、たとえば、インストールオレンジのデータセットを使用してデータベース、

 head(Orange)
Grouped Data: circumference ~ age | Tree
  Tree  age circumference
1    1  118            30
2    1  484            58
3    1  664            87
4    1 1004           115
5    1 1231           120
6    1 1372           142

#创建散点图和折线图代码示例
opar <- par(no.readonly = TRUE)
par(mfrow=c(1,2))
t1 <- subset(Orange, Tree==1)
plot(t1$age,t1$circumference,
     xlab="Age (days)",
     ylab="Circumference (mm)",
     main = "Orange Tree 1 Growth")
plot(t1$age,t1$circumference,type="b",
     xlab="Age (days)",
     ylab="Circumference (mm)",
     main = "Orange Tree 1 Growth")
par(opar)

ここに画像を挿入説明
パラメータタイプによって選択された線グラフタイプ
次のようにオプションのパラメータタイプ
Pを:点のみ
だけライン:Lは
○:固体点や線(すなわち、線は点に重ね)
B、C:点ワイヤ接続点(Cを描画しません)
S、Sは、ライン段差
Hを垂直線のヒストグラム
N:点や線がいずれかを生成しない(通常は、次のコマンドのために使用さは、軸を作成する)
のサンプルコードを

par(mfrow=c(2,4))
t1 <- subset(Orange, Tree==1)
plot(t1$age,t1$circumference,type="p",
     xlab="x",
     ylab="y",
     main = "type=p")
plot(t1$age,t1$circumference,type="l",
     xlab="x",
     ylab="y",
     main = "type=l")
plot(t1$age,t1$circumference,type="o",
     xlab="x",
     ylab="y",
     main = "type=o")
plot(t1$age,t1$circumference,type="b",
     xlab="x",
     ylab="y",
     main = "type=b")
plot(t1$age,t1$circumference,type="c",
     xlab="x",
     ylab="y",
     main = "type=c")
plot(t1$age,t1$circumference,type="s",
     xlab="x",
     ylab="y",
     main = "type=s")
plot(t1$age,t1$circumference,type="S",
     xlab="x",
     ylab="y",
     main = "type=S")
plot(t1$age,t1$circumference,type="h",
     xlab="x",
     ylab="y",
     main = "type=h")

ここに画像を挿入説明
これは、図、タイプ=生成された「P」の典型的なスキャッタグラム、TYPE =「B」最も一般的な折れ線グラフを生成するために、点BとCとの間とは異なるから見ることができる、または線間の利用可能性があるかどうかギャップがあります。
タイプ=「S」とタイプ=「S」は、段差ラインを生成するが、「s」はライン横オブジェクトであるが、その後、「S」が最初に増加し、その後、横線を描画、上昇
タイプ=を通じて「N」を使用することができます軸、タイトル、および他のグラフィカル特徴を作成し、曲線を追加するために必要なライン()および他の機能を使用します

第五に、時間の経過を示すオレンジの木に成長グラフィック
コード例を:

#为方便起见,将因子转换为数值型
par(opar)
Orange$Tree <- as.numeric(Orange$Tree)
ntrees <- max(Orange$Tree)

#range返回给定向量的最大值及最小值
xrange <- range(Orange$age)
yrange <- range(Orange$circumference)

#创建图形
plot(xrange,yrange,
     type="n",
     xlab="Age (days)",
     ylab="Circumference (mm)")
#设置线性颜色
colors <- rainbow(ntrees)
#设置线条类型
linetype <- c(1:ntrees)
#设置点的类型
plotchar <- seq(18, 18+ ntrees,1)

for (i in 1:ntrees) {
   tree <- subset(Orange,Tree==i)
   lines(tree$age,tree$circumference,
         type="b",
         lwd=2,
         lty=linetype[i],
         col=colors[i],
         pch=plotchar[i])
}

title("Tree Growth","example of line plot")

#添加图例
legend(xrange[1],yrange[2],legend = c(1,2,3,4,5),col=colors,lty=linetype,pch=plotchar)

ここに画像を挿入説明

公開された39元の記事 ウォン称賛11 ビュー10000 +

おすすめ

転載: blog.csdn.net/weixin_42712867/article/details/100129792