R 如何在聚合(…,hist)命令中输入标题?

R 如何在聚合(…,hist)命令中输入标题?,r,aggregate,R,Aggregate,我正在尝试自动创建带有适当标题的直方图 a <- c('aaa','bbb','ccc','aaa','bbb','ccc','aaa', 'bbb','ccc','aaa','bbb','ccc','aaa','bbb','ccc'); b <- rnorm(15,0,1); c <- data.frame(a,b); regions<-sort(unique(a)); 像这样的东西怎么样 a <- c('aaa','bbb','ccc','aaa

我正在尝试自动创建带有适当标题的直方图

 a <- c('aaa','bbb','ccc','aaa','bbb','ccc','aaa',
    'bbb','ccc','aaa','bbb','ccc','aaa','bbb','ccc');
 b <- rnorm(15,0,1);
 c <- data.frame(a,b);
regions<-sort(unique(a));

像这样的东西怎么样

a <- c('aaa','bbb','ccc','aaa','bbb','ccc','aaa',
       'bbb','ccc','aaa','bbb','ccc','aaa','bbb','ccc');
b <- rnorm(15,0,1);
c <- aggregate(b,by=list(a),FUN=sum)
barplot(c$x, names.arg=c$Group.1,space = 0)

像这样的东西怎么样

a <- c('aaa','bbb','ccc','aaa','bbb','ccc','aaa',
       'bbb','ccc','aaa','bbb','ccc','aaa','bbb','ccc');
b <- rnorm(15,0,1);
c <- aggregate(b,by=list(a),FUN=sum)
barplot(c$x, names.arg=c$Group.1,space = 0)

像这样的东西怎么样

a <- c('aaa','bbb','ccc','aaa','bbb','ccc','aaa',
       'bbb','ccc','aaa','bbb','ccc','aaa','bbb','ccc');
b <- rnorm(15,0,1);
c <- aggregate(b,by=list(a),FUN=sum)
barplot(c$x, names.arg=c$Group.1,space = 0)

像这样的东西怎么样

a <- c('aaa','bbb','ccc','aaa','bbb','ccc','aaa',
       'bbb','ccc','aaa','bbb','ccc','aaa','bbb','ccc');
b <- rnorm(15,0,1);
c <- aggregate(b,by=list(a),FUN=sum)
barplot(c$x, names.arg=c$Group.1,space = 0)

a如果您试图创建三个直方图,每个区域一个,适当地命名,您可以使用
sapply
避免显式编写循环

# rename your data.frame c as df
colnames(df) <- c('region', 'val')
# filter your df by region, and create a title histogram
sapply(regions, function(x) hist(df[df['region'] == x, 2], main=x)
#将data.frame c重命名为df

colnames(df)如果您试图创建三个直方图,每个区域一个,适当地命名,您可以使用
sapply
来避免显式编写循环

# rename your data.frame c as df
colnames(df) <- c('region', 'val')
# filter your df by region, and create a title histogram
sapply(regions, function(x) hist(df[df['region'] == x, 2], main=x)
#将data.frame c重命名为df

colnames(df)如果您试图创建三个直方图,每个区域一个,适当地命名,您可以使用
sapply
来避免显式编写循环

# rename your data.frame c as df
colnames(df) <- c('region', 'val')
# filter your df by region, and create a title histogram
sapply(regions, function(x) hist(df[df['region'] == x, 2], main=x)
#将data.frame c重命名为df

colnames(df)如果您试图创建三个直方图,每个区域一个,适当地命名,您可以使用
sapply
来避免显式编写循环

# rename your data.frame c as df
colnames(df) <- c('region', 'val')
# filter your df by region, and create a title histogram
sapply(regions, function(x) hist(df[df['region'] == x, 2], main=x)
#将data.frame c重命名为df

colnames(df)这里有两个ggplot解决方案

# create more interesting example
set.seed(1)   # for reproducibility
a <- rep(c('aaa','bbb','ccc'), each=100)
b <- rnorm(length(a),mean=rep(1:3, each=100))
c <- data.frame(a,b)

library(ggplot2)
ggplot(c, aes(x=b, fill=a, color=a)) + 
  geom_histogram(binwidth=0.5, position="identity", alpha=.5)

这里有两种解决方案

# create more interesting example
set.seed(1)   # for reproducibility
a <- rep(c('aaa','bbb','ccc'), each=100)
b <- rnorm(length(a),mean=rep(1:3, each=100))
c <- data.frame(a,b)

library(ggplot2)
ggplot(c, aes(x=b, fill=a, color=a)) + 
  geom_histogram(binwidth=0.5, position="identity", alpha=.5)

这里有两种解决方案

# create more interesting example
set.seed(1)   # for reproducibility
a <- rep(c('aaa','bbb','ccc'), each=100)
b <- rnorm(length(a),mean=rep(1:3, each=100))
c <- data.frame(a,b)

library(ggplot2)
ggplot(c, aes(x=b, fill=a, color=a)) + 
  geom_histogram(binwidth=0.5, position="identity", alpha=.5)

这里有两种解决方案

# create more interesting example
set.seed(1)   # for reproducibility
a <- rep(c('aaa','bbb','ccc'), each=100)
b <- rnorm(length(a),mean=rep(1:3, each=100))
c <- data.frame(a,b)

library(ggplot2)
ggplot(c, aes(x=b, fill=a, color=a)) + 
  geom_histogram(binwidth=0.5, position="identity", alpha=.5)

那么你想要三个直方图,一个由每个“区域”的数据过滤?什么是样本输出?那么你想要三个直方图,一个由每个“区域”的数据过滤?什么是样本输出?那么你想要三个直方图,一个由每个“区域”的数据过滤?什么是样本输出?那么你想要三个直方图,根据每个“区域”的数据过滤的一个?样本输出是什么?我在寻找每个区域的直方图,如果我没有正确表达我自己,很抱歉。我在寻找每个区域的直方图,如果我没有正确表达我自己,很抱歉。我在寻找每个区域的直方图,对不起,如果我没有正确地表达我自己。我在寻找每个地区的直方图,如果我没有正确地表达我自己,对不起。