Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

投稿:地区分布图及其应用 黄湘云 #1027

Merged
merged 68 commits into from
May 22, 2022
Merged

投稿:地区分布图及其应用 黄湘云 #1027

merged 68 commits into from
May 22, 2022

Conversation

XiangyunHuang
Copy link
Member

@XiangyunHuang XiangyunHuang commented Apr 23, 2022

非常感谢您的PR, 如果您是在为主站投稿, 请将PR的标题改为"投稿:标题+作者的形式",如:
"投稿: 数据通灵术 杜亚磊"
并保留下面的内容.

  • 投稿者请注意
    • 主编审核确认接收
    • 主编安排审稿人
    • 审稿、修改

至此,投稿部分的工作结束

  • 编辑部分工作
    • 文字编辑做校对工作。需校对文章分类,目前的文章分类包括:COS访谈,R会议,R语言,推荐文章,新闻动态,机器学习,统计之都,统计图形,统计应用,统计模型,统计计算,统计软件,职业事业。不得擅自增加分类。
    • 微信编辑、发布,阅读原文附主站链接,文末附作者介绍
    • 论坛帖子负责人发帖,粘贴链接,提供 forum_id 加入文章
    • 合并 PR,发布文章

投稿指南在这里,有任何问题,可以直接在PR留言,其他问题请联系: editor@cos.name

@XiangyunHuang

This comment was marked as off-topic.

@XiangyunHuang
Copy link
Member Author

我已邀请沥今 @zhanglj37 来审稿

Copy link
Member

@yihui yihui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

解决 https://d.cosx.org/d/423119/10 的问题。

Comment on lines +92 to +95
.full-width {
width: 100vw;
margin-left: calc(50% - 50vw);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不知道为什么 100vw 在我的浏览器里预览是超宽的,浏览器会有横向滚动条。所以我把宽度减了 1 字宽。图标题可以移动到与正文对齐。

Suggested change
.full-width {
width: 100vw;
margin-left: calc(50% - 50vw);
}
@media (max-width: 930px) {
.full-width {
width: calc(100vw - 1em);
margin-left: calc(50% - 50vw + .5em);
}
.full-width .caption {
margin-left: calc(50% - 450px + 1em);
}
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

一顿乱试,终于好了,下面是最终的调整结果:

.full-width {
  width: 100vw;
  margin-left: calc(50% - 50vw);
}

.full-width .caption {
  margin-left: calc(50% - 450px + 1em);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

但你这并没有解决我上面说的超宽导致水平滚动条的问题啊。图标题和正文文本对齐是个相对简单的问题(原理我在论坛帖子里解释过了),图片宽度定义 100vw 却超宽是我没弄明白的问题。看下面的截图,底部有滚动条。

image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那到是有点奇怪,我是一通乱试,没有下方滚动条,我的浏览器是 Google 版本 101.0.4951.41
其实即使有滚动条,我觉得也很好了。

map

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那是有点怪。我用同样版本的 Chrome 还是有滚动条。Firefox 和 Safari 皆是如此。

Copy link
Member Author

@XiangyunHuang XiangyunHuang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reorder() 对城镇按癌症死亡率排序没有起到预期的作用,代码如下,猜测是 ggplot2 的 BUG

data(USCancerRates, package = "latticeExtra")
showtext::showtext_auto()
us_cancer_rates <- reshape(
  data = USCancerRates,
  # 需要转行的列,也可以用列序号代替
  varying = c(
    "LCL95.male", "rate.male", "UCL95.male",
    "LCL95.female", "rate.female", "UCL95.female"
  ),
  times = c("男性", "女性"), # 构成新列 sex 的列值
  v.names = c("LCL95", "rate", "UCL95"), # 列转行 列值构成的新列,指定名称
  timevar = "sex", # 列转行 列名构成的新列,指定名称
  idvar = c("state", "county"), # 可识别城镇的编码
  # 原数据有 3041 行,性别字段只有两个取值,转长格式后有 2*3041 行
  new.row.names = 1:(2 * 3041),
  direction = "long"
)
alabama_us_cancer_rates = subset(x = us_cancer_rates, subset = state == "Alabama")
library(ggplot2)
ggplot(data = alabama_us_cancer_rates, aes(x = rate, xmin = LCL95, xmax = UCL95, y = reorder(county, rate), colour = sex)) +
  geom_pointrange() +
  labs(x = "癌症死亡率", y = "城镇", colour = "性别") +
  theme_minimal()

这是分组排序 reorder 其实不是 ggplot2 的 BUG,正确的代码如下:

ggplot(data = alabama_us_cancer_rates, aes(x = rate, xmin = LCL95, xmax = UCL95, y = reorder(county, rate, max), colour = sex)) +
  geom_pointrange() +
  labs(x = "癌症死亡率", y = "城镇", colour = "性别") +
  theme_minimal()

@XiangyunHuang
Copy link
Member Author

@zhanglj37 已经按照修改意见都修改了,辛苦抽空再看下。

@zhanglj37
Copy link
Contributor

我没什么问题了,只有表达上的几处细节

提炼了其间的关联关系,一些绘图经验 -> 关联关系重复,保留一个即可, 这句话改成“总结了不同方案间的关系和一些绘图经验”?

众所周知,后者是新一代更好的工具,因此接下来的示例都将基于 sf 包。感觉众所周知可以删了哈哈

各社区家庭年收入和白人占比相关性比较低,要是相关性到达统计课本里常见的 50%,甚至更高,那社会问题就大发了!结合图 20 也不难看出稳定正向的关系,平均来说,社区的白人占比增加一个百分点,家庭年收入增加 438 美元。 -> “要是..大发了!”感觉可以删掉?家庭年收入增加 438 美元中家庭年收入写成“该地区家庭平均年收入”?

考虑空间因素,R2 肯定要比 0.147 大多了 -> 改成 由此可见,引入地区分布图帮助我们更直观地了解了白人占比和家庭收入的关系 ?

@XiangyunHuang
Copy link
Member Author

谢谢 @zhanglj37 ,已根据反馈修改,审稿修改阶段完成了 🚀

@XiangyunHuang
Copy link
Member Author

未来展望部分,我加一段,感觉这样比较紧扣本文内容

在单变量情形中,已用 7 种绘图方法展示美国各郡年平均癌症死亡率,还可以补充 ggplot2 + ggspatialggplot2 + maps 两种历史方法。

在多变量情形中,对美国社区调查数据,还可以继续做一些拓展分析,比如:

  • 在社区级调查数据的基础上,分郡建立家庭年收入和白人占比的线性模型,获得各郡的相关性。进一步,将范围从北卡州扩展到全美,展示相关性在美国各郡的空间分布。
  • 在线性模型的基础上,添加空间效应,引入空间自相关模型来量化家庭年收入与白人占比的空间分布。
  • 基于过去 10-20 年的美国社区调查数据,分析高、低收入圈在空间集聚的过程和速度。

@XiangyunHuang XiangyunHuang changed the title 投稿:专题地图及其应用 黄湘云 投稿:地区分布图及其应用 黄湘云 May 14, 2022
@yufree yufree merged commit b5a8faa into master May 22, 2022
@yufree yufree deleted the choropleth-map branch May 22, 2022 02:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
主站日常管理
  
Awaiting triage
Development

Successfully merging this pull request may close these issues.

None yet

4 participants