问题描述
我正在阅读一些有关R函数“图”的教材,并且我已经有很多问题。首先,我想了解'type'参数如何工作以及何时工作。
我的代码:
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,xlab="Countries",ylab="Gold",main="Gold Medals")
在第一个图中,当我尝试更改type参数时,我得到了相应更改的图形。像这样
但是,当我尝试对另一个真实数据集执行相同操作时(见下文),它不起作用。 数据集如下所示:
'type'参数如何工作?谢谢
解决方法
无论使用哪种“类型”参数,都可以看到相同类型的图,原因是数据集的“国家/地区”列是“因子”类型。
尝试将另一列作为'x'或定义x=as.numeric(countries)
,您将看到不允许使用某些'type'值,而type="p"
将显示带有点的图。