如何更改状态箱图的颜色?

问题描述 投票:1回答:1

我正在尝试更改Statebins地图的颜色。我是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()

这会生成带有一系列蓝色的地图。如何更改颜色?不管我在Google上尝试过什么,总是会抛出此错误:

Error in ggplot2_scale_function(...) : could not find function "ggplot2_scale_function"

非常感谢任何帮助。谢谢!

r colors data-visualization
1个回答
0
投票

尚无您的数据,但我伪造了一个示例,正如Ian指出的那样,问题是找到合适的规模。

library(dplyr)
library(ggplot2)
library(statebins)

state_facts <- as.data.frame(state.x77) %>%
mutate(state = rownames(.))
state_facts$share <- cut(state_facts$Illiteracy, 
                         breaks = 3, 
                         labels = c("No sales tax", 
                                    "Exempts digital goods", 
                                    "Taxes digital goods"))


state_facts %>%
  statebins(value_col = "share", name = "", ggplot2_scale_function = scale_fill_brewer) +
  labs(title = "Which states tax digital products?") +
  theme_statebins(legend_position = "right")

“”

reprex package(v0.3.0)在2020-05-12创建

© www.soinside.com 2019 - 2024. All rights reserved.