gpt4 book ai didi

r - 如何更改 statebins map 的颜色?

转载 作者:行者123 更新时间:2023-12-04 10:02:30 25 4
gpt4 key购买 nike

我正在尝试更改 statebins map 的颜色。我是 R 的新手,仍然在学习很多东西,谷歌搜索并没有真正帮助。

这是样本的样子:

   fipst stab                state color
1 37 NC North Carolina 2
2 1 AL Alabama 2
3 28 MS Mississippi 2
4 5 AR Arkansas 2
5 47 TN Tennessee 2
6 45 SC South Carolina 1
7 23 ME Maine 2
49 32 NV Nevada 1
50 15 HI Hawaii 2
51 11 DC District of Columbia 2

digitaltax <- structure(list(fipst = c(37L, 1L, 28L, 5L, 47L, 45L, 23L, 32L,15L, 11L), stab = c("NC", "AL", "MS", "AR", "TN", "SC", "ME","NV", "HI", "DC"), state = c("North Carolina", "Alabama", "Mississippi","Arkansas", "Tennessee", "South Carolina", "Maine", "Nevada","Hawaii", "District of Columbia"), color = c(2L, 2L, 2L, 2L,2L, 1L, 2L, 1L, 2L, 2L)), row.names = c(1L, 2L, 3L, 4L, 5L, 6L,7L, 49L, 50L, 51L), class = "data.frame")

==X==============================================================X==

mutate(
digitaltax,
share = cut(color, breaks = 3, labels = c("No sales tax", "Exempts digital goods", "Taxes digital goods"))
) %>%
statebins(
value_col = "share", font_size = 2.5,
ggplot2_scale_function = scale_fill_brewer,
name = ""
) +
labs(title = "Which states tax digital products?") + theme_statebins()

这将生成具有一系列蓝色的 map 。我怎样才能改变颜色?无论我在谷歌上尝试过并找到什么,它总是会引发此错误:
Error in ggplot2_scale_function(...) : could not find function "ggplot2_scale_function"

任何帮助都将不胜感激。谢谢!

最佳答案

一种方法是使用命名 RColorBrewer味觉 brewer_pal = :

library(statebins)
statebins(digitaltax,
value_col = "color",
breaks = length(unique(digitaltax$share)),
labels = unique(digitaltax$share),
brewer_pal = "Dark2") +
labs(title = "Which states tax digital products?")

enter image description here

执行此命令以查看所有口味:
library(RColorBrewer)
display.brewer.all()

enter image description here

关于r - 如何更改 statebins map 的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61759621/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com