在地块上循环播放

编程入门 行业动态 更新时间:2024-10-27 03:43:25
本文介绍了在地块上循环播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我尝试生成很多图并将它们保存在单独的文件中。每个图都应该基于一个数据框中的变量。

当使用变量的数量时,这是有效的:

for(i in names(df)[19:20]){ png(paste(i,png,sep =。),width = 400 ,高度= 400) print(ggplot(df)+ geom_histogram(aes_string(x = i),binwidth = 0.4)+ theme_bw()) dev.off()}

但是,如果我使用变量名而不是有序数。我不明白为什么。

for(i in names(df)[c(varname1,varname2, (gfplot(df)+ geom_histogram(aes_string(png,sep =。),width = 400,height = 400) (x = i),binwidth = 0.4)+ theme_bw()) dev.off()}

在后一个问题中,我得到以下错误消息(如果它与第一个例子中的变量完全相同):

错误:StatBin需要一个连续的x变量,x变量是离散的,也许你需要stat =count?

有什么想法?

解决方案

names(df)是一个未命名的向量,所以选择它没有意义

for(i in c(varname1,varname2,varname3)){ png(paste(i,png,sep =。),width = 400,height = 400 ) print(ggplot(d f)+ geom_histogram(aes_string(x = i),binwidth = 0.4)+ theme_bw()) dev.off()}

I try to generate a lot of plots and save them in separate files. Each plot should be based on a variable from a dataframe.

This works when using the numbers of the variables:

for(i in names(df)[19:20]) { png(paste(i, "png", sep = "."), width = 400, height = 400) print(ggplot(df) + geom_histogram(aes_string(x= i), binwidth= 0.4) + theme_bw()) dev.off() }

However, it doesn't work if I'm using variable names instead of the ordered number. I don't understand why.

for(i in names(df)[c("varname1","varname2","varname3")]) { png(paste(i, "png", sep = "."), width = 400, height = 400) print(ggplot(df) + geom_histogram(aes_string(x= i), binwidth= 0.4) + theme_bw()) dev.off() }

I get the following error message at the latter question (if it's exactly the same variable as in the first example):

"Error: StatBin requires a continuous x variable the x variable is discrete. Perhaps you want stat="count"? "

Any ideas?

解决方案

names(df) is an unnamed vector, so it doesn't make sense to select named values from that vector.

What you're looking for is

for(i in c("varname1","varname2","varname3")) { png(paste(i, "png", sep = "."), width = 400, height = 400) print(ggplot(df) + geom_histogram(aes_string(x= i), binwidth= 0.4) + theme_bw()) dev.off() }

更多推荐

在地块上循环播放

本文发布于:2023-07-19 17:03:24,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:地块

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!