[英]The 'type' parameter in R plot function
我正在閱讀 R function '情節'的一些教材,我已經有很多問題了。 首先,我想了解“類型”參數是如何工作的以及何時工作。
我的代碼:
t<-seq(from=0, to=10, by=0.1)
y<-sin(t)
#changing the type parameter here works, I can see the difference
#between, e.g., line or histogram
plot(x=t, y=y,
type="h",
xlab="Angle",
ylab="Sine",
col="red",
main="Sine function")
rio <- read.csv(".../Rio2016.csv")
#see screenshot below for what the data look like
View(rio)
countries <- rio$Country
gold <- rio$Gold
silver <- rio$Silver
bronze <- rio$Bronze
# changing the type param here does not work. No matter
# what I tried, it always display the same thing
plot(x=countries,y=silver, type="h",
xlab="Countries",
ylab="Gold",
col="red",
main="Gold Medals")
在第一個 plot 中,當我嘗試更改類型參數時,我得到相應更改的圖形。 像這樣
但是,當我嘗試對另一個真實數據集(見下文)執行相同操作時,它不起作用。 數據集如下所示:
“類型”參數如何工作? 謝謝
無論“類型”參數如何,您看到相同類型的 plot 的原因是數據集的“國家”列屬於“因子”類型。
嘗試將另一列作為 'x' 或定義x=as.numeric(countries)
您將看到一些 'type' 值是不允許的,而type="p"
將顯示帶有點的 plot。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.