r - 如何在与我的散点图中的点不同的颜色 brewer 调色板中使用回归线?
问题描述
使用 GapMinder 数据,我用不同的大陆回归线制作了下面的图:
这是代码:
ggplot(gapminder_82,
aes(gdpPercap, lifeExp, color = continent)) +
geom_point() +
scale_x_log10() +
scale_color_brewer(palette = "Set2") +
geom_smooth(method = "lm", se = F)
问题是这些线条并不是真正可见的。所以我想使用来自 color brewer 的 2 种不同的调色板。点的Pastel2,但我想用“Dark2”作为线条。它会使线条脱颖而出。
我该怎么做?
解决方案
您可以对点使用填充点形状,允许您对点使用填充比例,对线条使用颜色:
ggplot(gapminder_82,
aes(gdpPercap, lifeExp)) +
# Make the edge color for the points totally transparent
geom_point(aes(fill = continent), shape = 21, size = 3, colour = "#FFFFFF00") +
scale_x_log10() +
geom_smooth(aes(color = continent), method = "lm", se = F) +
scale_fill_brewer(palette = "Pastel2") +
scale_color_brewer(palette = "Dark2") +
theme_bw()
结果:
推荐阅读
- loops - 添加 GUI 后,PixelSearch 在 AutoHotkey 脚本中无法正常工作
- sql - 具有多列的唯一聚集索引上的全文索引
- python-2.7 - SSLError:[Errno 1] _ssl.c:510:错误:14090086:SSL 例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败
- create-react-app - 公共 JS 文件中的 yarn build + create-react-app + env 变量
- javascript - 如何捕获浏览器控制台中显示的异常?
- spring-boot - Spring boot + apache CXF Soap 客户端
- hyperledger - 通过概念查询一组参与者
- c# - 如何在 C# 中使用多个 IF 条件
- scala.js - 如何在 scala.js 中访问 node.js process.env.ENV_VARIABLE?
- javascript - 如何根据特定用户输入在 JavaScript 中显示警报