我想重新创建流行与苏打地图。我正在使用state
库中的maps
。这是我正在使用的代码。
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
为渐变着色。有没有更好的方法可以解决这个问题?
答案 0 :(得分:0)
因此,我可以在美学内使用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")
有什么办法使它更像放射状的阴影吗?