如何更改 ggforce 包的 geom_voronoi_tile 函数中区域的颜色
How to change color of the areas in geom_voronoi_tile function of ggforce package
我想更改 ggforce 包中 geom_voronoi_tile
创建的 voronoi 多边形的颜色,但无法这样做。我尝试使用以下代码:
library(tidyverse)
library(ggforce)
library(RColorBrewer)
col1 <- c("#d53e4f", "#f46d43", "#3288bd")
Species <- c("setosa", "versicolor", "virginica")
Tabla1 <- data.frame(Species, col1)
iris1 <- iris %>%
left_join(Tabla1, by = "Species")
ggplot(iris1, aes(Sepal.Length, Sepal.Width) ) +
geom_voronoi_tile(aes(fill = Species, group = -1L, color = col1)) +
geom_voronoi_segment() +
geom_point()
这是我的会话信息
R version 3.4.4 (2018-03-15)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods
[7] base
other attached packages:
[1] RColorBrewer_1.1-2 ggforce_0.2.0.9000 agricolae_1.2-8
[4] mxmaps_0.1 forcats_0.4.0 stringr_1.4.0
[7] dplyr_0.8.0.1 purrr_0.3.2 readr_1.1.1
[10] tidyr_0.8.2 tibble_2.0.1 ggplot2_3.1.0
[13] tidyverse_1.2.1
要更改多边形填充的值,您可以使用 scale_fill_manual()
将颜色设置为 Species
。请注意,我删除了 color = col
参数,因为它将多边形的边界设置为一种颜色,在 geom_voronoi_*()
中由 geom_voronoi_segment()
.
处理
ggplot(iris1, aes(Sepal.Length, Sepal.Width) ) +
geom_voronoi_tile(aes(fill = Species, group = -1L)) +
geom_voronoi_segment() +
scale_fill_manual(values = col1, breaks = Species) +
geom_point()
要更改多边形边的颜色,您可以在 geom_voronoi_segment()
中设置 aes(colour = Species)
。
ggplot(iris1, aes(Sepal.Length, Sepal.Width) ) +
geom_voronoi_tile(aes(fill = Species, group = -1L)) +
geom_voronoi_segment(aes(colour = Species, group = -1L)) +
geom_point() +
scale_colour_manual(values = col1, breaks = Species)
我想更改 ggforce 包中 geom_voronoi_tile
创建的 voronoi 多边形的颜色,但无法这样做。我尝试使用以下代码:
library(tidyverse)
library(ggforce)
library(RColorBrewer)
col1 <- c("#d53e4f", "#f46d43", "#3288bd")
Species <- c("setosa", "versicolor", "virginica")
Tabla1 <- data.frame(Species, col1)
iris1 <- iris %>%
left_join(Tabla1, by = "Species")
ggplot(iris1, aes(Sepal.Length, Sepal.Width) ) +
geom_voronoi_tile(aes(fill = Species, group = -1L, color = col1)) +
geom_voronoi_segment() +
geom_point()
这是我的会话信息
R version 3.4.4 (2018-03-15)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods
[7] base
other attached packages:
[1] RColorBrewer_1.1-2 ggforce_0.2.0.9000 agricolae_1.2-8
[4] mxmaps_0.1 forcats_0.4.0 stringr_1.4.0
[7] dplyr_0.8.0.1 purrr_0.3.2 readr_1.1.1
[10] tidyr_0.8.2 tibble_2.0.1 ggplot2_3.1.0
[13] tidyverse_1.2.1
要更改多边形填充的值,您可以使用 scale_fill_manual()
将颜色设置为 Species
。请注意,我删除了 color = col
参数,因为它将多边形的边界设置为一种颜色,在 geom_voronoi_*()
中由 geom_voronoi_segment()
.
ggplot(iris1, aes(Sepal.Length, Sepal.Width) ) +
geom_voronoi_tile(aes(fill = Species, group = -1L)) +
geom_voronoi_segment() +
scale_fill_manual(values = col1, breaks = Species) +
geom_point()
要更改多边形边的颜色,您可以在 geom_voronoi_segment()
中设置 aes(colour = Species)
。
ggplot(iris1, aes(Sepal.Length, Sepal.Width) ) +
geom_voronoi_tile(aes(fill = Species, group = -1L)) +
geom_voronoi_segment(aes(colour = Species, group = -1L)) +
geom_point() +
scale_colour_manual(values = col1, breaks = Species)