R绘图功能中的“类型”参数

问题描述

我正在阅读一些有关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参数时,我得到了相应更改的图形。像这样

enter image description here

但是,当我尝试对另一个真实数据集执行相同操作时(见下文),它不起作用。 数据集如下所示:

enter image description here

无论我尝试过哪种“类型”,它始终显示如下:

enter image description here

'type'参数如何工作?谢谢

解决方法

无论使用哪种“类型”参数,都可以看到相同类型的图,原因是数据集的“国家/地区”列是“因子”类型。

尝试将另一列作为'x'或定义x=as.numeric(countries),您将看到不允许使用某些'type'值,而type="p"将显示带有点的图。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...