r - 当我尝试运行 for 循环时,为什么 R 会删除我文件中的所有信息?
问题描述
我准备了一个建模程序,它生成 26 个单独的文件,我需要在 R 中以相同的方式绘制等高线图 - 我计划重复运行该程序,因此一直在尝试创建一个循环来创建和保存所有 26 个图每次运行的文件。
在我运行创建绘图的函数时,它会从输入电子表格中删除所有数据(即文件大小从 1.2Mb 变为 0Mb) - 以前没有这样做,谁能解释出了什么问题?
我的数据样本:
Z X T
0 0 0
0 0.005 0
0 0.01 0
0 0.015 0
(等等 84k 行)
我的代码:
# List all files in folder to be plotted
filenames <- list.files(path=".",
pattern="csv",
full.names=TRUE)
#Creates a contour plot in ggplot of the variable in xz space
makeplot <- function(filename) {
data <- read.csv(file = filename)
ggplot(data=data, mapping = aes(x = data[,2],
y = data[,1],
z = data[,3])) +
geom_raster(data=data, aes(fill=data[,3]), show.legend=TRUE, interpolate =
FALSE) +
scale_fill_gradient(limits=range(data[,3]), high = 'red', low = 'white') +
geom_contour(bins = 50, colour = "black") +
xlab(label = "Distance from ridge axis") +
ylab(label = "Depth") +
theme_classic()+
coord_cartesian(
ylim = c(0,1), xlim = c(0,2))+
scale_x_continuous(expand = c(0, 0)) +
scale_y_continuous(expand = c(0, 0)) +
guides(fill=guide_legend(title="Yb concentration")) +
theme(legend.position="bottom")
}
# Repeat plotting
for(f in filenames) {
makeplot(f)
}
任何帮助,将不胜感激!
解决方案
推荐阅读
- c# - 将 typeof 与变量一起使用
- python - 如何从数据框中的两列的除法中找到最小值
- html - 为什么我的侧边栏被推到主页内容下方?
- reactjs - 在 ReactJS 中使用 Firebase 对数据进行排序
- python - 按两个标准对列进行排序
- python - 根据班级更改车身颜色
- sql - SQL Server:如何将字符串“ddMMM”替换或转换为日期“MMMdd”?
- python - Python - 将编码字符串的转义字符转换为 %
- jsf - 如何使用 Java EE Security @CustomFormAuthenticationMechanismDefinition 重定向到原始请求 URL
- java - 如何延迟 CallNextHookEx 或 PostMessage 的返回以模拟延迟的鼠标事件?