Как изменить цвет областей в функции geom_voronoi_tile пакета ggforce - PullRequest
1 голос
/ 02 мая 2019

Я хотел бы изменить цвета полигонов voronoi, созданных geom_voronoi_tile из пакета ggforce, но не смог этого сделать.Я попытался с помощью следующего кода:

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   

1 Ответ

0 голосов
/ 02 мая 2019

Чтобы изменить значения заливки полигона, вы можете использовать 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()

enter image description here

Чтобы изменить цвета ребер многоугольника, вы можете установить aes(colour = Species) внутри geom_voronoi_segment().

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)

enter image description here

...