r - R绘图函数中的“类型”参数
问题描述
我正在阅读 R 函数“情节”的一些教材,我已经有很多问题了。首先,我想了解“类型”参数是如何工作的以及何时工作。
我的代码:
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")
在第一个图中,当我尝试更改类型参数时,我得到相应更改的图形。像这样
但是,当我尝试对另一个真实数据集(见下文)执行相同操作时,它不起作用。数据集如下所示:
“类型”参数如何工作?谢谢
解决方案
无论“类型”参数如何,您都看到相同类型的绘图的原因是数据集的“国家”列属于“因子”类型。
尝试将另一列作为“x”或定义x=as.numeric(countries)
您将看到某些“类型”值是不允许的,而type="p"
将显示带有点的图。
推荐阅读
- laravel - Laravel 自定义验证规则引用其他请求参数
- dialogflow-es - DialogFlow 使用外部应用程序/API 进行身份验证
- python - ModuleNotFoundError:Docker 容器中没有名为“companyname”的模块与 Django
- windows - 从 Windows PowerShell 中的命令中提取特定值
- python - 虽然循环在聊天机器人中不能作为语音转文本的意图
- php - 为什么电子邮件地址永远不会收到测试?
- uipath - Web Scraping 返回空数据表 UiPath
- r - 如何将 lapply 与需要向量作为参数的函数一起使用
- java - 我想对类运行时中的单个实例进行更多说明 [JAVA]
- pentaho - mysql 存储库如何在 Pentaho 用户控制台中工作?