【发布时间】:2016-09-16 07:54:53
【问题描述】:
我有一个新生儿兄弟姐妹的体重和性别数据样本,并希望将它们绘制在 R 中的常见 2x2 点图上,如下所示在 Stata 中完成: 2x2 plot of birthweight of first compared to second child
stata代码是这个
egen sex1sex2=group(sex1st sex2nd),label
scatter weight2nd weight1st,by(sex1sex2) aspect(1) scheme(s1mono)
R中数据的结构是这样的:
> str(siblings)
'data.frame': 1000 obs. of 5 variables:
$ sex1st : int 1 1 1 2 1 1 2 1 2 2 ...
$ sex2nd : int 1 2 1 2 2 2 1 2 2 1 ...
$ weight1st: int 3740 3060 3650 3688 3740 3550 3850 3680 2390 3600 ...
$ weight2nd: int 3740 3620 3700 3726 3000 3700 4020 4310 2250 3250 ...
$ difw : int 0 560 50 38 -740 150 170 630 -140 -350 ...
只需要考虑 1:4。 在性方面,1=男孩,2=女孩。在原始 .dta 文件中,它们被标记。
我找到了这个帖子,我认为这是要走的路,但我不知道如何理解它:Dot Plots with multiple categories - R
非常感谢您的帮助。
【问题讨论】:
-
不只是 Stata 的名字:我想大多数人都会称这些散点图。
-
嗨尼克。我认为你完全正确。散点图是更正确的术语。我目前正在学习生物统计学课程,课程材料是通过 Stata 代码提供的,但我一直致力于使用 R,所以我有时会遇到一些小问题。