r - 使用 R 绘图
问题描述
我想multiplot
使用r绘制图形,并且我想要每个站点在 X 轴上的值,并且图中的不同线是 M、T、L 和 G,但是在代码的开头,我得到了一个错误,
$ 运算符对原子向量无效
Graphdata <- as.data.frame(multiplot)
par(mfrow=c(4,3))
plot(Graphdata$Sites$A, Graphdata$f, ylim=c(0,16), xlab="Number of years",
ylab="Relative density", lwd=2)
lines(Graphdata$Sites$M, type="l", col="blue", lwd=2)
lines(Graphdata$Sites$T, type="l", col="green", lwd=2)
lines(Graphdata$Sites$L, type="l", col="grey", lwd=2)
lines(Graphdata$Sites$G, type="l", col="orange", lwd=2)
我的一些数据是
解决方案
您需要按如下方式进行子集化:
SiteA<-Graphdata[Graphdata$Sites=="A",]
plot(SiteA$f,SiteA$M)
par(mfrow=c(1,1))
也就是说,我是 的粉丝,tidyverse
并认为它会给你一个更简单的解决方案。你需要reshape2
你的数据,虽然gather
可以做得很好。编辑您还需要决定如何处理缺失值。
library(tidyverse)
Graphdata %>%
gather("MySite","MyValue",3:ncol(.)) %>%
filter(Sites=="A") %>%
ggplot(aes(`f`,MyValue,col=MySite))+geom_point()+geom_line()
推荐阅读
- c# - 如何使第二个数据网格名称在 C# 中可见?
- angular - MSAL、Angular 和 ASP.NET Core 的 CORS 错误
- reactjs - 当作为道具传递给功能组件时,反应功能未定义
- html - 无法更改页脚的背景颜色
- python - Django /admin/ 不接受正确的凭据。我如何解决它?
- html - 为什么从 thymyleaf 片段链接库需要双链接?
- selenium-webdriver - webdriverjs中的上下文单击问题
- python - 在 android 上使用 kivy 运行 rospy
- amazon-web-services - AWS SES 将电子邮件保存到 s3 存储桶
- javascript - 将选项输出到选择的小 javascript 不起作用