R ggplot:带有调色板“ Greens”的geom_point,如何获得黑点边界?

问题描述

我用ggplot()绘制散点图,并使用特定的调色板,即'Greens'。基本上,我对这种情节非常满意,但是我希望每个点周围都有一个黑色边框。我的情节代码是:

p <- ggplot(data = df.dataCorrelation,aes(x = prod1,y = prod2)) +
     geom_point(aes(color = year)) +
     geom_smooth(method = "lm",se = FALSE,color = "#007d3c") +
     theme_classic() +
     theme(legend.position = "none") +
     theme(panel.background = element_blank()) +
     scale_color_brewer(palette = 'Greens') +   # customized color palette
     xlab(product1) +
     ylab(product2) +
     ggtitle("Correlation Scatter Plot (Pearson)") +
     theme(plot.title = element_text(hjust = 0.5,face = "bold"))

,并提供以下图形:

scatterPlot

我知道我可以使用以下命令绘制黑色边框:

geom_point(aes(color = year,fill = ?),color = "black",pch = 21)

但这不适用于我选择的调色板,因为我不知道在fill = ?中使用什么

解决方法

尝试一下。

这里的数据是可重复的例子

library(dplyr)

product1 <- "product1"
product2 <- "product2"
df.dataCorrelation <- iris %>% rename(prod1 = Petal.Length,prod2 = Petal.Width,year  = Species)

这里是您的代码

library(ggplot2)

ggplot(data = df.dataCorrelation,aes(x = prod1,y = prod2)) +
 geom_point(aes(fill = year),colour = "black",shape = 21,size = 3) +
 geom_smooth(method = "lm",se = FALSE,color = "#007d3c") +
 theme_classic() +
 theme(legend.position = "none") +
 theme(panel.background = element_blank()) +
 scale_fill_brewer(palette = 'Greens') +   # customized color palette
 xlab(product1) +
 ylab(product2) +
 ggtitle("Correlation Scatter Plot (Pearson)") +
 theme(plot.title = element_text(hjust = 0.5,face = "bold"))

enter image description here

注意:

  • 我写了colour = "black"
  • 我将scale_colour_brewer更改为scale_fill_brewer
  • 我写了fill = year而不是colour = year

(我增加点数的原因仅在于看不到最终结果)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...