[英]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.