我想重新创建POP与苏打地图。我正在使用maps
库中的state
。这是我正在使用的代码。
states = map_data("state")
states%>%
full_join(soft_drinks_plot, by = c("region" = "State"))%>%
ggplot()+
geom_polygon(aes(x = long, y = lat, group = group,
fill = max_choice, color = max_choice), color = "white")+
scale_fill_gradient2(aesthetics = "color")
我的soft_drinks_plot
数据框看起来像这样:
State Pop Soda Coke Other Total max_choice per_max
alabama 153 582 2849 665 4249 Coke 0.671
alaska 324 636 60 92 1112 Soda 0.572
arizona 586 2799 437 174 3996 Soda 0.700
arkansas 154 347 1442 80 2023 Coke 0.713
california 925 20119 2892 1941 25877 Soda 0.777
这是重新创建它的代码:
soft_drinks_plot <- read.table(text =
"State Pop Soda Coke Other Total max_choice per_max
alabama 153 582 2849 665 4249 Coke 0.671
alaska 324 636 60 92 1112 Soda 0.572
arizona 586 2799 437 174 3996 Soda 0.700
arkansas 154 347 1442 80 2023 Coke 0.713
california 925 20119 2892 1941 25877 Soda 0.777",
header = TRUE, stringsAsFactors = FALSE)
我希望颜色是max_choice
,我希望使用per_max
对梯度进行阴影。有更好的方法吗?
,这样我就可以使用美学内部的 alpha = per_max
淡化地图。
states%>%
full_join(soft_drinks_plot, by = c("region" = "State"))%>%
ggplot()+
geom_polygon(aes(x = long, y = lat, group = group,
fill = max_choice, alpha = per_max), color = "black")
有什么方法可以使其更像是径向阴影?