比较 R 中的三个变量并通过在 ggplot 上分组来映射它

问题描述

我想比较 R 中的三个变量。我在弄清楚分析这些数据的编码时遇到了麻烦,想知道是否有人可以提供帮助。

此表查看邮政编码,按行业和类型(A、B、C、D)将它们分开。我想基本上按 zip 中的类型(A、B、C、D)总结所有值。从那里我想排除特定数字以下的所有 zip 以仅查看相关数据点。

最后 - 我试图在美国地图 ggplot 上绘制此图 - 按行业按颜色绘制所有用户...但 ggplot 不直观,我无法正确绘制点。

原始数据:https://docs.google.com/spreadsheets/d/1R1NeFTuvvhqnxG-SgABevJjPflyaG_P1btmwyD2hB-c/edit?usp=sharing

到目前为止我的代码

ftable(body_industry$postalcode,body_industry$industry,body_industry$reclass_bodytype)

#My initial thought was to use addmargins(ftable(body_industry...) 
but this doesn't seem to be working as the data set doesn't sum up properly.

 Zip     Industry           A    B    C    D
 94801   artistic           0    0    0    0
         banking            0    0    0    0
         clerical           0    0    0    0
         computer           0    1    0    0
         construction       1    0    0    0
         education          1    0    0    0
         entertainment      0    0    0    0
         executive          0    0    0    0
         hospitality        0    0    0    0
         law                0    0    0    0
         medicine           0    0    0    0
         military           0    0    0    0
         political          0    0    0    0
         retired            0    0    0    0
         sales              0    0    0    1
         science            0    0    0    0
         student            0    0    0    0
         transportation     0    0    0    0
         unemployed         0    0    0    0
94803    artistic           2    2    2    1
         banking            2    2    1    0
         clerical           0    2    1    0
         computer           0    2    0    1
         construction       5    2    0    0
         education          1    4    4    0
         entertainment      2    2    0    0
         executive          2    0    0    0
         hospitality        0    2    0    0
         law                2    0    1    0
         medicine           2    5    3    0
         military           0    1    1    0
         political          1    1    0    0
         retired            0    1    0    0
         sales              2    5    0    0
         science            2    4    0    0
         student            4    0    3    1
         transportation     0    1    1    0
         unemployed         0    0    0    0
94804    artistic           4   10    7    2
         banking            5    0    3    0
         clerical           0    2    3    1
         computer           7    6    5    2
         construction       7    7    6    0
         education         11    8    9    1
         entertainment      4    1    3    1
         executive          3    4    3    1
         hospitality        2    7    3    0
         law                2    5    0    1
         medicine           9    7    6    1
         military           2    2    0    0
         political          3    0    1    0
         retired            0    1    2    1
         sales             10    6    0    2
         science           10    5    3    1
         student           13   15   13    5
         transportation     1    1    1    0
         unemployed         1    1    3    0
94806    artistic           4    2    0    2
         banking            1    2    3    0
         clerical           1    1    0    0
         computer           4    2    2    0
         construction       4    4    3    1
         education          8    1    4    0
         entertainment      1    0    0    0
         executive          1    3    0    0
         hospitality        0    2    3    0
         law                1    1    2    0
         medicine           4    4    2    1
         military           2    2    1    0
         political          1    3    0    1
         retired            0    0    0    0
         sales              6    6    3    0
         science            3    4    2    1
         student           10    5    6    2
         transportation     3    2    2    0
         unemployed         0    1    3    1
94901    artistic          22    9   13    7
         banking           20   10    6    1
         clerical           2    0    5    1
         computer          21   12    4    6
         construction      18    2    1    0
         education         18   17   14    3
         entertainment     11    7    3    0
         executive         13    4    3    5
         hospitality        7    4    2    0
         law                5    4    4    0
         medicine          28   18   12    3
         military           0    0    0    0
         political          3    3    0    0
         retired            4    2    3    1
         sales             27   13    9    3
         science           15    1    4    0
         student           10   18    5   10
         transportation     0    0    2    0
         unemployed         0    1    2    1
94904    artistic           4    1    0    1
         banking            7    3    1    0
         clerical           0    1    0    0
         computer           1    2    1    0
         construction       1    0    0    0
         education          1    2    1    1
         entertainment      0    0    1    0
         executive          5    5    0    0
         hospitality        1    0    0    0
         law                0    1    0    1
         medicine           5    3    3    1
         military           0    0    0    0
         political          1    0    0    0
         retired            0    0    0    0
         sales              5    2    1    0
         science            5    1    2    0
         student            0    2    0    0
         transportation     0    0    0    0
         unemployed         0    0    0    0

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)