R - 在过滤不需要的数据后,自动从多个csv文件创建散点图 [英] R - create a scatter plot from a number of csv files automatically after filtering unwanted data

查看:231
本文介绍了R - 在过滤不需要的数据后,自动从多个csv文件创建散点图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我附加了一个CSV样本文件,其中有100个CSV文件,

它的许多列和19个顶部行应该过滤,其余数据应该用于绘制图表并以更有用的格式导出图表。

这些数据是由Netlogo行为空间生成的,我无法找到直接可视化输出的好方法,所以每次实验后我都有很多csv文件。

数据文件: https:/ /www.dropbox.com/s/nj243qcs6sx6fu8/Rates.csv
示例输出: https://www.dropbox.com/s/suomh0vwsfzisj4/SampleGraph.jpg



例如粗体字段是我需要的阴谋:



x,y ,颜色,笔下来,x, y ,颜色,下笔? ,x, y ,颜色,笔向下,x, y ,颜色,笔向下?

谢谢;)

解决方案

这是一个答案:

 dat < -  read.csv('Rates.csv',stringsAsFactors = FALSE,skip = 19)
colnames(dat)[which(names(dat)%in%c (y,y.1,y.2,y.3))] <-c(Age,Revenge,Homicide,Hunger)

require(reshape2)
tmp< - melt(dat,id.vars =x,measure.vars = c(Age,R (a,b,b,b,b,c,c,evenge,Homicide,Hunger))
require(ggplot2)
ggplot(tmp,aes(x,value))+
geom_point )+
xlab(time)+
ylab(units)+
ggtitle(我的CSV文件)+
labs(color =my variables )


以下是您可以如何将它与您的100个CSV文件一起使用...

  files<  - (dir(C:/ my-csv-files,recursive = TRUE,full.names = TRUE,pattern =\\ (csv | CSV)$))
listcsvs< - lapply(files,function(i)read.csv(i,stringsAsFactors = FALSE,skip = 19))
names(listcsvs)< ; - 文件
require(reshape2)
require(ggplot2)
for(i in 1:length(files)){
tmp< - melt(dat,id.vars =x,measure.vars = c(y,y.1,y.2,y.3))
print(ggplot(tmp,aes(x,value) )+
geom_point(aes(color = factor(varia (b)(b)(b)(b)(b)(b)(b)(b) b}


I have attached a sample CSV file which I have 100 of them,

A number of its columns and its 19 top rows should be filtered and rest of data should be used to plot graphs and export graphs in a more usable format.

These data are generated by Netlogo behavior space, and I could not find a good way to visualize the output directly, so what I have after each experiment is many csv files.

data file: https://www.dropbox.com/s/nj243qcs6sx6fu8/Rates.csv sample output : https://www.dropbox.com/s/suomh0vwsfzisj4/SampleGraph.jpg

for example bold columns are the ones I need to plot :

x,y,color,pen down?,x,y,color,pen down?,x,y,color,pen down?,x,y,color,pen down?

thanks ;)

解决方案

Here's an answer for this one plot:

dat <- read.csv('Rates.csv', stringsAsFactors = FALSE, skip = 19)
colnames(dat)[which(names(dat) %in% c("y", "y.1", "y.2", "y.3"))] <- c("Age", "Revenge", "Homicide", "Hunger")

require(reshape2)
tmp <- melt(dat, id.vars = "x", measure.vars = c("Age", "Revenge", "Homicide", "Hunger"))
require(ggplot2)
ggplot(tmp,aes(x, value)) + 
        geom_point(aes(colour = factor(variable))) +
        xlab("time") +
        ylab("units") +
        ggtitle("My CSV file") +
        labs(colour = "my variables")

And here's how you might use it with your 100s of CSV files...

files <- (dir("C:/my-csv-files", recursive=TRUE, full.names=TRUE, pattern="\\.(csv|CSV)$"))
listcsvs <- lapply(files, function(i) read.csv(i,  stringsAsFactors = FALSE, skip = 19))
names(listcsvs) <- files
require(reshape2)
require(ggplot2)
for (i in 1:length(files)) { 
  tmp <- melt(dat, id.vars = "x", measure.vars = c("y", "y.1", "y.2", "y.3"))
  print( ggplot(tmp,aes(x, value)) + 
    geom_point(aes(colour = factor(variable))) +
    xlab("time") +
    ylab("units") +
    ggtitle(names(listcsvs[i])) )
  )
}

这篇关于R - 在过滤不需要的数据后,自动从多个csv文件创建散点图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆