r - 如何在不同颜色的啤酒调色板中获得与散点图中的点不同的回归线?

标签 r ggplot2 colors colorbrewer

使用 GapMinder 数据,我用不同的大陆回归线绘制了下面的图:

scatter plot with regression lines

这是代码:

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()

结果:

enter image description here

关于r - 如何在不同颜色的啤酒调色板中获得与散点图中的点不同的回归线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52306691/

相关文章:

Rf_error 和 Rf_warning 定义

r - Shiny 的应用程序中的条件边栏取决于所选的选项卡

android - R.attr.colorPrimary 颜色类型的预期资源

colors - 创建color brewer并获取其平均值

r - 如何在ggplot2中将百分比四舍五入到小数点后两位

ios - 全局背景颜色变化

r - 如何将Excel日期格式转换为R中的正确日期

r - 使用 grid.arrange 指定标题颜色

r - geom_label 中的上标星

r - 在函数R中时,ggplot2似乎不起作用