ggplot graphing of proportions of observations within categories

后端 未结 2 796
别那么骄傲
别那么骄傲 2020-12-08 22:59

I am looking for advice on better ways to plot the proportion of observations in various categories.

I have a dataframe that looks something like this:



        
2条回答
  •  南笙
    南笙 (楼主)
    2020-12-08 23:35

    I will understand if this isn't really what you're looking for, but I found your description of what you wanted very confusing until I realized that you were simply trying to visualize your data in a way that seemed very unnatural to me.

    If someone asked me to produce a graph with the proportions within each category, I'd probably turn to a segmented bar chart:

    ggplot(df,aes(x = cat2,fill = cat1)) + 
        geom_bar(position = "fill")
    

    enter image description here

    Note the y axis records proportions, not counts, as you wanted.

提交回复
热议问题