我正在关注此链接:ggplot2 bar plot with two categorical variables
我的问题非常相似 - 我需要做OP所需要的但我需要将计数条除以另一个因素。
让我说明一下:
> var response_cat has values 0,1 (categories of a response)
>
> var group indicates belonging to a group (0,1)
>
> var item indicates the name of an item (20 strings with codes like LY1, GN6,...)
我需要绘制如下图表: x轴每个项目有两个条形(每组) y轴的相对频率为1
任何想法?
谢谢你!答案 0 :(得分:1)
我们可以使用protected void ddlitemname_TextChanged (object sender, EventArgs e)
{
DataSet ds = Common.ExecuteQuery("select * from Tbl_Item_Master where Category='" + ddlitemname.SelectedItem.Text + "'");
if (ds.Tables[0].Rows.Count > 0)
{
txthscode.Text = ds.Tables[0].Rows[0]["Hscode"].ToString();
txtselect.Text = ds.Tables[0].Rows[0]["specification"].ToString();
txttax.Text = ds.Tables[0].Rows[0]["Tax"].ToString();
lblphoto.Text = ds.Tables[0].Rows[0]["Photo"].ToString();
}
}
facet_wrap
library(tidyverse)
df %>%
group_by_at(names(.)) %>%
summarise(n = n()) %>%
ggplot(., aes(x = Fruit, y = n, fill = Bug)) +
geom_bar(stat = "identity") +
facet_wrap(~ group)