在R中绘制数据集的一个%

发布于 01-22 19:09 字数 606 浏览 1 评论 0原文

我正在尝试在整个人群中绘制人口类别。

因此,如果我有:

df <- data.frame (population= c("a", "a", "a", "a","b", "b","b","b","c","c"),
              income= c("10", "15", "12", "19","45", "42","41","43","23","23")
              )

如何在密度图中绘制整个df的“ A”的比例?如下图中所示:

”“在此处输入图像描述”

编辑

我要绘制的是值A,B和C的密度。不是收入价值。在此密度图内,我只想阴影“ A”值。 基本上,我想以密度为阴影绘制来自数据帧列的值的比例。

这是我正在研究的数据集的链接。我想绘制“自雇”变量中“自雇”的值的比例。

I am trying to plot a population category inside the whole population.

So if I have:

df <- data.frame (population= c("a", "a", "a", "a","b", "b","b","b","c","c"),
              income= c("10", "15", "12", "19","45", "42","41","43","23","23")
              )

How can I plot the proportion of "a" from the whole df in a density plot? Like in the following picture:

enter image description here

EDIT

What I am trying to plot is the density of the values a, b and c. Not the income values. And inside this density plot, I want to shadow only the 'a' values.
Basically, I want to shadow in a density plot the proportion of a value from a dataframe column.

This is the link of the dataset I am working on. I want to plot the proportion of the value "Self-Employed" in the "workclass" variable.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情何以堪。 2025-01-29 19:09:39

您的问题确实不清楚。但是也许你的意思是这样

hist(as.numeric(df[df$population=='a','income']), freq = F)

your question is not clear indeed. But maybe you meant something like this

hist(as.numeric(df[df$population=='a','income']), freq = F)
も星光 2025-01-29 19:09:39

最后,我在 so 中找到了一个链接。 。这是我的最终代码:

ggplot(censo, aes(x = factor(workclass))) +  
    geom_bar(aes(y = (..count..)/sum(..count..))) + 
    scale_y_continuous(labels = percent)

Finally, I found a link in S.O.. This is my final code:

ggplot(censo, aes(x = factor(workclass))) +  
    geom_bar(aes(y = (..count..)/sum(..count..))) + 
    scale_y_continuous(labels = percent)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文