为什么ggplot scale_colour_手册使用形状文件生成不正确的填充颜色
目标 我试图在2017年法国选举结果的绘图中绘制一张地图,让每个选民都能看到获胜政党的颜色 问题 当我用为什么ggplot scale_colour_手册使用形状文件生成不正确的填充颜色,r,ggplot2,shapefile,R,Ggplot2,Shapefile,目标 我试图在2017年法国选举结果的绘图中绘制一张地图,让每个选民都能看到获胜政党的颜色 问题 当我用geom_sf映射法国选民的形状文件时,fill参数无法识别我为每个政党的颜色输入的十六进制值。相反,它为每一方分配了一种新的颜色 我的地图应该是这样的颜色 但ggplot目前的颜色是这样的 代码 我有一份所有法国选民的表格,在R中看起来像 df dept_circ party_2017 dept_nom geometry 1 00
geom_sf
映射法国选民的形状文件时,fill参数无法识别我为每个政党的颜色输入的十六进制值。相反,它为每一方分配了一种新的颜色
我的地图应该是这样的颜色
但ggplot目前的颜色是这样的
代码
我有一份所有法国选民的表格,在R中看起来像
df
dept_circ party_2017 dept_nom geometry
1 001_01 LR Ain POLYGON ((4.887938 46.41241...
2 001_02 LR Ain POLYGON ((4.728168 45.94598...
3 001_03 LREM Ain POLYGON ((5.570681 45.75369...
4 001_04 LREM Ain POLYGON ((4.739192 46.04677...
5 001_05 LR Ain POLYGON ((5.247852 45.94869...
6 002_01 LREM Aisne POLYGON ((3.310763 49.68271...
7 002_02 LR Aisne POLYGON ((3.055322 49.83207...
8 002_03 PS Aisne POLYGON ((3.3149 49.95589, ...
9 002_04 LREM Aisne POLYGON ((3.036076 49.3252,...
10 002_05 LREM Aisne POLYGON ((2.957951 49.22691...
我为每一方创建了一套相应的颜色(前五方如下所示)
但结果产生了巨大的影响
geom\u sf无法识别我输入的十六进制颜色,这有什么错呢?使用
scale\u fill\u manual()
而不是scale\u color\u manual()
使用
比例填充手册()
而不是比例颜色手册()
您是否尝试过使用
scale\u fill\u manual
替代?您是否尝试过scale\u fill\u manual
替代?
colours_fra_parties <- c(
"PCF" = "#E4002B",
"DVG" = "#FFC0C0",
"FI" = "#C9462C",
"FI (E)"= "#C9462C",
"PS" = "#ED1651") # ... and so on for every single party
df %>%
ggplot() +
geom_sf(
aes(fill = party_2017),
colour = "#000000", # Colour the border around each electorate
lwd = 0.1 # Specify width of the border lines
) +
coord_sf( # Centre the map on metropolitan France
xlim = c(-5, 10), # Degrees longitude west (-) and east (+) of GMT to map
ylim = c(41.5, 51.5)) + # Degrees latitude south (-) and north (+) of the equator
scale_colour_manual( # Feed geom_sf the correct colours of each party
values = colours_fra_parties)