简体   繁体   English

如何 Plot 一个在 X 轴上有两个分类变量的条形图(一个由另一个嵌套,但都可见),以及其他变量作为填充?

[英]How to Plot a Bar Graph with Two Categorical Variables on X-Axis (one nested by the other, but both visible), and other variables as fill?

I have a dataset with two categorical variables, region and function .我有一个包含两个分类变量regionfunction的数据集。 In total there are 92 regions, divided into 13 functional categories.共有92个区域,分为13个功能类别。 In addition to these regions belonging to a functional category, they are also identified as either white , gray , or other .除了属于功能类别的这些区域之外,它们还被标识为whitegrayother Each region is associated with a density value that will be plotted on the y-axis.每个区域都与一个密度值相关联,该密度值将绘制在 y 轴上。 For Example:例如:

Region地区 Function Function Matter事情 Density密度
AMB AMB Cranial颅骨 Gray灰色的 4 4个
bsc平衡计分卡 Visual视觉的 White白色的 0.4 0.4
LG LG Visual视觉的 Gray灰色的 30.5 30.5
RET休息时间 Thalamic丘脑 Gray灰色的 25 25
eml电子邮件 Thalamic丘脑 White白色的 15 15
cpt cpt Motor马达 Other其他 5 5个

I wish to create a graph similar to this, where the year dates at the top would be my functional categories, the x-axis labels would be my region names, and the bar fill would denote white/gray.我希望创建一个与此类似的图表,其中顶部的年份日期将是我的功能类别,x 轴标签将是我的区域名称,填充条将表示白色/灰色。 However, an important distinction is I would want all of my 92 regions to be present along the x-axis once, divided into functional groups.然而,一个重要的区别是我希望我的所有 92 个区域都沿着 x 轴出现一次,分为功能组。

Example Graph示例图

I've created graphs showing just the total averages of the regions within my functional groups as well as a graph of all regions averages separately.我创建了仅显示我的功能组内区域的总平均值的图表,以及单独显示所有区域平均值的图表。 I would like to create something similar, but with all the functional group's associated regions present in the graph and grouped by function. Essential a merger between these two types of graphs, in addition to a fill variable for the bars.我想创建一些类似的东西,但所有功能组的相关区域都出现在图中并按 function 分组。除了条形的填充变量之外,这两种类型的图之间的必要合并。

Graph of Region Averages区域平均值图

Graph of Functional Group Averages功能组平均值图

This is a pretty barebones question as I am fairly new to R and stackoverflow.这是一个非常简单的问题,因为我对 R 和 stackoverflow 还很陌生。 I will be busy today but can provide any additional information necessary as soon as I am able to.我今天会很忙,但可以尽快提供任何必要的额外信息。 Any help is appreciated.任何帮助表示赞赏。 Thank you!谢谢!

Six data is not much.六个数据不多。 I don't have an example to pull a good example from, but maybe you're looking for something like that:我没有一个例子可以从中得出一个很好的例子,但也许你正在寻找这样的东西:

library(ggplot2)
ggplot(data, aes(Density, fill= Matter)) + 
    geom_bar(width=.5) + 
    facet_grid(~Function + Region, scales="free_x", space="free") 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用ggplot2包将X轴上的2个分类变量和两个连续变量绘制为“填充”? - How to plot 2 categorical variables on X-axis and two continuous variables as “fill” using ggplot2 package? 如何在R中的x轴上绘制带有分类变量的散点图 - How to plot a scatterplot with categorical variables in the x-axis in R ggplot,条形图中用于interaction()因子变量的嵌套X轴 - ggplot, nested X-Axis for interaction() factor variables in bar plot 如何在R轴的x轴上制作带有两个分类变量的散点图 - How to make scatterplot with two categorical variables on x-axis in R Plot 一条线和一个点 plot 在 x 轴上有一个分类变量,两个变量定义组 - Plot a line and dot plot with a categorical variable on the x-axis, and two variables defining the groups 如何为R中跨x轴镜像的两个变量创建条形图? - How do you create a bar plot for two variables mirrored across the x-axis in R? 在 x 轴上绘制四个分类变量的条形图,每个变量都有两个水平作为填充,具有各自的百分比 - Barplot four categorical variables on x-axis, each with two levels as fill, with respective percentages 带有嵌套分类变量和R中的纹理填充的堆积条形图 - Stacked bar plot with nested categorical variables and textured fill in R 如何更改 ggplot2 中分类变量的 x 轴大小? - How to change the size of x-axis for categorical variables in ggplot2? 如何从 ggplot2 中的两个分类变量创建 x 轴标签? - How do I create x-axis labels from two categorical variables in ggplot2?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM