循环创建多个ggplots
我有一个数据集,该数据集具有变量周,社会经济状况(从1-5起)以及每周和每个社会经济地位的独特家庭数量。
现在,我想创建5个GGPLOTS,这是每个社会经济地位的一个图。每个情节都应显示几周来一个社会经济地位的独特家庭数量的发展。
我考虑过要使用for循环,但到目前为止,我找不到有效的解决方案。如果有人可以帮助我,那会很棒。
I have a data set that has the variables week, socioeconomic status (from 1-5) and number of unique households for each week and each socioeconomic status.
Now, I want to create 5 ggplots, one plot for each socioeconomic status. Each plot should show the development of the number of unique households for one socioeconomic status over several weeks.
I thought about using a for loop but so far I couldn't find a solution that works. Would be great if someone could help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您的数据是
df
,并且您有列Week
,ses
和nhh
。如果您只想通过SES可视化绘图,则可以使用facet_wrap()
,如:如果您想要绘图的数据框架,则可以执行此操作:
输出:
如果您想要一个列表情节对象,您可以做到这一点
Let's say your data is
df
and you have columnsweek
,ses
, andnhh
. If you just want to visualize the plot by ses, you can usefacet_wrap()
, like this:If you would like a dataframe of plots, you can do this:
Output:
If you would like a list of plot objects, you can do this